diff --git a/client/client_test.go b/client/client_test.go index a6ca5c036..d516eface 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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) { diff --git a/yorkie/types/client_info.go b/yorkie/types/client_info.go index f532dec54..dea4be448 100644 --- a/yorkie/types/client_info.go +++ b/yorkie/types/client_info.go @@ -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 }