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

test: Unit test fixing of TestEventlogManager_UpdateSegmentReplicas #467

Merged
merged 3 commits into from
Feb 28, 2023
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: 17 additions & 5 deletions internal/controller/eventbus/eventlog/eventlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,11 @@ func TestEventlogManager_ScaleSegmentTask(t *testing.T) {
So(util.MapLen(&utMgr.globalBlockMap), ShouldEqual, (defaultAppendableSegmentNumber*2+1)*3)

utMgr.stop()
// avoid data race during UT
head = el2.head()
el2.lock()
head.State = StateFrozen
el2.unlock()
So(err, ShouldBeNil)
time.Sleep(50 * time.Millisecond)
So(el.size(), ShouldEqual, defaultAppendableSegmentNumber+1)
Expand Down Expand Up @@ -783,21 +786,30 @@ func TestEventlogManager_UpdateSegmentReplicas(t *testing.T) {
kvCli := kv.NewMockClient(ctrl)
utMgr.kvClient = kvCli

ctx := stdCtx.Background()
el, err := newEventlog(ctx, &metadata.Eventlog{
ID: vanus.NewTestID(),
EventbusID: vanus.NewTestID(),
EventbusName: "ut",
}, kvCli, false)
So(err, ShouldBeNil)
utMgr.eventLogMap.Store(el.md.ID.Key(), el)

blk := &metadata.Block{
ID: vanus.NewTestID(),
Capacity: 64 * 1024 * 1024,
SegmentID: 0,
ID: vanus.NewTestID(),
Capacity: 64 * 1024 * 1024,
EventlogID: el.md.ID,
}
seg := createTestSegment(vanus.NewTestID())
seg.EventLogID = el.md.ID
seg.Replicas.Term = 3
utMgr.globalSegmentMap.Store(seg.ID.Key(), seg)
utMgr.globalBlockMap.Store(blk.ID.Key(), blk)

ctx := stdCtx.Background()
kvCli.EXPECT().Set(ctx, filepath.Join(metadata.SegmentKeyPrefixInKVStore, seg.ID.String()),
gomock.Any()).Times(1).Return(nil)

err := utMgr.UpdateSegmentReplicas(ctx, vanus.NewTestID(), 3)
err = utMgr.UpdateSegmentReplicas(ctx, vanus.NewTestID(), 3)
So(err, ShouldEqual, errors.ErrBlockNotFound)

err = utMgr.UpdateSegmentReplicas(ctx, blk.ID, 3)
Expand Down