Skip to content

Commit

Permalink
Fix check already attached document
Browse files Browse the repository at this point in the history
In AttachDocument, [ErrDocumentAlreadyAttached] error is returned if
there is a document in the current client field. However, AttachDocument
also need to check the document attachment status to determine whether to
return an error or not.
  • Loading branch information
dc7303 authored and hackerwins committed Dec 3, 2020
1 parent efd0e5f commit e75c25f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ func TestClientAndDocument(t *testing.T) {
err = c1.Detach(ctx, doc)
assert.NoError(t, err)
assert.False(t, doc.IsAttached())

err = c1.Attach(ctx, doc)
assert.NoError(t, err)
assert.True(t, doc.IsAttached())

err = c1.Detach(ctx, doc)
assert.NoError(t, err)
assert.False(t, doc.IsAttached())
})

t.Run("causal nested array test", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion yorkie/types/client_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (i *ClientInfo) AttachDocument(docID primitive.ObjectID) error {

hexDocID := docID.Hex()

if i.hasDocument(hexDocID) {
if i.hasDocument(hexDocID) && i.Documents[hexDocID].Status == DocumentAttached {
return ErrDocumentAlreadyAttached
}

Expand Down

0 comments on commit e75c25f

Please sign in to comment.