Skip to content

Commit ead2a35

Browse files
committed
catch expanded events
1 parent 0fa4b98 commit ead2a35

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

internal/verifier/change_stream_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/10gen/migration-verifier/mslices"
89
"github.com/pkg/errors"
910
"github.com/samber/lo"
1011
"github.com/stretchr/testify/require"
@@ -35,6 +36,12 @@ func TestChangeStreamFilter(t *testing.T) {
3536
// terminates that verifier, updates the source cluster, starts a new
3637
// verifier with change stream, and confirms that things look as they should.
3738
func (suite *IntegrationTestSuite) TestChangeStreamResumability() {
39+
suite.Require().NoError(
40+
suite.srcMongoClient.
41+
Database(suite.DBNameForTest()).
42+
CreateCollection(suite.Context(), "testColl"),
43+
)
44+
3845
func() {
3946
verifier1 := suite.BuildVerifier()
4047
ctx, cancel := context.WithCancel(context.Background())
@@ -43,7 +50,7 @@ func (suite *IntegrationTestSuite) TestChangeStreamResumability() {
4350
suite.Require().NoError(err)
4451
}()
4552

46-
ctx, cancel := context.WithCancel(context.Background())
53+
ctx, cancel := context.WithCancel(suite.Context())
4754
defer cancel()
4855

4956
_, err := suite.srcMongoClient.
@@ -213,14 +220,21 @@ func (suite *IntegrationTestSuite) TestNoStartAtTime() {
213220
}
214221

215222
func (suite *IntegrationTestSuite) TestWithChangeEventsBatching() {
216-
verifier := suite.BuildVerifier()
223+
ctx := suite.Context()
217224

218-
ctx, cancel := context.WithCancel(context.Background())
219-
defer cancel()
225+
db := suite.srcMongoClient.Database(suite.DBNameForTest())
226+
coll1 := db.Collection("testColl1")
227+
coll2 := db.Collection("testColl2")
228+
229+
for _, coll := range mslices.Of(coll1, coll2) {
230+
suite.Require().NoError(db.CreateCollection(ctx, coll.Name()))
231+
}
232+
233+
verifier := suite.BuildVerifier()
220234

221235
suite.Require().NoError(verifier.StartChangeStream(ctx))
222236

223-
_, err := suite.srcMongoClient.Database("testDb").Collection("testColl1").InsertOne(ctx, bson.D{{"_id", 1}})
237+
_, err := coll1.InsertOne(ctx, bson.D{{"_id", 1}})
224238
suite.Require().NoError(err)
225239
_, err = suite.srcMongoClient.Database("testDb").Collection("testColl1").InsertOne(ctx, bson.D{{"_id", 2}})
226240
suite.Require().NoError(err)
@@ -239,6 +253,7 @@ func (suite *IntegrationTestSuite) TestWithChangeEventsBatching() {
239253
500*time.Millisecond,
240254
"the verifier should flush a recheck doc after a batch",
241255
)
256+
242257
}
243258

244259
func (suite *IntegrationTestSuite) TestEventBeforeWritesOff() {

mslices/slices.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package mslices
2+
3+
// This package complements the Go standard library’s package of the
4+
// same name with broadly-useful tools that the standard library lacks.
5+
6+
// Of returns a slice out of the given arguments. It’s syntactic sugar
7+
// to capitalize on Go’s type inference, similar to
8+
// [this declined feature proposal](https://github.com/golang/go/issues/47709).
9+
func Of[T any](pieces ...T) []T {
10+
return append([]T{}, pieces...)
11+
}

mslices/slices_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package mslices
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/suite"
7+
)
8+
9+
type mySuite struct {
10+
suite.Suite
11+
}
12+
13+
func TestUnitTestSuite(t *testing.T) {
14+
suite.Run(t, &mySuite{})
15+
}
16+
17+
func (s *mySuite) Test_Of() {
18+
slc := Of(12, 23, 34)
19+
20+
s.Assert().IsType([]int{}, slc, "expected type")
21+
22+
a := []int{1, 2, 3}
23+
b := Of(a...)
24+
a[0] = 4
25+
26+
s.Assert().Equal(1, b[0], "should copy slice")
27+
}

0 commit comments

Comments
 (0)