Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBG-3715 fix TestDCPFeedEventTypes #6832

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions base/dcp_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,31 +690,32 @@ func TestDCPFeedEventTypes(t *testing.T) {
gocbv2Bucket, err := AsGocbV2Bucket(bucket.Bucket)
require.NoError(t, err)

testOver := make(chan struct{})
foundEvent := make(chan struct{})
docID := t.Name()
var dcpMutationCas uint64
var dcpMutationRevNo uint64
var dcpDeletionCas uint64
var dcpDeletionRevNo uint64
// create callback
callback := func(event sgbucket.FeedEvent) bool {
fmt.Printf("!! event: %+v\n", event)
// other doc events can happen from previous tests
if docID != string(event.Key) {
return true
}
switch event.Opcode {
case sgbucket.FeedOpMutation:
defer func() {
foundEvent <- struct{}{}
}()
dcpMutationCas = event.Cas
dcpMutationRevNo = event.RevNo
require.NotEqual(t, uint64(0), dcpMutationCas)
require.NotEqual(t, uint64(0), dcpMutationRevNo)
case sgbucket.FeedOpDeletion:
defer close(testOver)
defer close(foundEvent)

dcpDeletionCas = event.Cas
dcpDeletionRevNo = event.RevNo
// FIXME: I am surprised these values are zero
require.NotEqual(t, uint64(0), dcpDeletionCas)
require.NotEqual(t, uint64(0), dcpDeletionRevNo)
}
Expand All @@ -735,15 +736,22 @@ func TestDCPFeedEventTypes(t *testing.T) {
writeMutationCas, err := collection.WriteWithXattrs(ctx, docID, 0, 0, []byte(`{"foo":"bar"}`), map[string][]byte{xattrName: xattrBody}, nil)
require.NoError(t, err)

// make sure mutation is processed
timeout := time.After(time.Second * 5)
select {
case <-foundEvent:
case <-timeout:
t.Fatalf("timeout waiting for doc mutation")
}

deleteMutationCas, err := collection.Remove(docID, writeMutationCas)
require.NoError(t, err)

timeout := time.After(time.Second * 5)
select {
case <-testOver:
case <-foundEvent:
require.NoError(t, dcpClient.Close())
case <-timeout:
t.Fatalf("timeout waiting for doc write/deletion to complete")
t.Fatalf("timeout waiting for doc deletion")
}
require.NoError(t, <-doneChan)

Expand Down
Loading