Skip to content

Commit

Permalink
CBG-3715 fix TestDCPFeedEventTypes (#6832)
Browse files Browse the repository at this point in the history
  • Loading branch information
torcolvin authored May 16, 2024
1 parent 30d0291 commit c946bc8
Showing 1 changed file with 15 additions and 7 deletions.
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

0 comments on commit c946bc8

Please sign in to comment.