Skip to content

Commit b6a6059

Browse files
authored
CBG-2412: Leaking rest/replicator_test.go goroutines (#6181)
1 parent 469b1e7 commit b6a6059

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

rest/replicatortest/replicator_collection_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ func TestReplicatorMissingCollections(t *testing.T) {
469469

470470
// Make rt2 listen on an actual HTTP port, so it can receive the blipsync request from rt1
471471
srv := httptest.NewServer(passiveRT.TestPublicHandler())
472+
defer srv.Close()
472473

473474
// Build passiveDBURL with basic auth creds
474475
passiveDBURL, _ := url.Parse(srv.URL + "/" + passiveRT.GetDatabase().Name)

rest/replicatortest/replicator_test.go

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6919,6 +6919,7 @@ func TestReplicatorConflictAttachment(t *testing.T) {
69196919
})
69206920
}
69216921
}
6922+
69226923
func TestConflictResolveMergeWithMutatedRev(t *testing.T) {
69236924
base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)
69246925

@@ -7570,45 +7571,27 @@ func TestReplicatorDeprecatedCredentials(t *testing.T) {
75707571
func TestReplicatorCheckpointOnStop(t *testing.T) {
75717572
base.RequireNumTestBuckets(t, 2)
75727573

7573-
passiveRT := rest.NewRestTester(t, nil)
7574-
defer passiveRT.Close()
7575-
7576-
adminSrv := httptest.NewServer(passiveRT.TestAdminHandler())
7577-
defer adminSrv.Close()
7578-
7579-
activeRT := rest.NewRestTester(t, nil)
7580-
defer activeRT.Close()
7574+
activeRT, passiveRT, remoteURL, teardown := rest.SetupSGRPeers(t)
7575+
defer teardown()
75817576
activeCtx := activeRT.Context()
75827577

75837578
// Disable checkpointing at an interval
75847579
activeRT.GetDatabase().SGReplicateMgr.CheckpointInterval = 0
7585-
err := activeRT.GetDatabase().SGReplicateMgr.StartReplications(activeCtx)
7586-
require.NoError(t, err)
75877580

75887581
rev, doc, err := activeRT.GetSingleTestDatabaseCollectionWithUser().Put(activeCtx, "test", db.Body{})
75897582
require.NoError(t, err)
75907583
seq := strconv.FormatUint(doc.Sequence, 10)
75917584

7592-
replConfig := `
7593-
{
7594-
"replication_id": "` + t.Name() + `",
7595-
"remote": "` + adminSrv.URL + `/db",
7596-
"direction": "push",
7597-
"continuous": true,
7598-
"collections_enabled": ` + strconv.FormatBool(!activeRT.GetDatabase().OnlyDefaultCollection()) + `
7599-
}
7600-
`
7601-
resp := activeRT.SendAdminRequest("POST", "/{{.db}}/_replication/", replConfig)
7602-
rest.RequireStatus(t, resp, 201)
7603-
7585+
activeRT.CreateReplication(t.Name(), remoteURL, db.ActiveReplicatorTypePush, nil, true, db.ConflictResolverDefault)
76047586
activeRT.WaitForReplicationStatus(t.Name(), db.ReplicationStateRunning)
76057587

76067588
err = passiveRT.WaitForRev("test", rev)
76077589
require.NoError(t, err)
76087590

7609-
_, err = activeRT.GetDatabase().SGReplicateMgr.PutReplicationStatus(t.Name(), "stop")
7610-
require.NoError(t, err)
7611-
activeRT.WaitForReplicationStatus(t.Name(), db.ReplicationStateStopped)
7591+
// stop active replicator explicitly
7592+
ar, ok := activeRT.GetDatabase().SGReplicateMgr.GetLocalActiveReplicatorForTest(t, t.Name())
7593+
assert.True(t, ok)
7594+
require.NoError(t, ar.Stop())
76127595

76137596
// Check checkpoint document was wrote to bucket with correct status
76147597
// _sync:local:checkpoint/sgr2cp:push:TestReplicatorCheckpointOnStop

0 commit comments

Comments
 (0)