Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 committed Sep 21, 2023
1 parent e3e346a commit 7ced8f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions pkg/utils/syncutil/flexible_wait_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ func (fwg *FlexibleWaitGroup) Wait() {
}
fwg.Unlock()
}

// getCount returns the current count of the FlexibleWaitGroup.
// It is only used for testing.
func (fwg *FlexibleWaitGroup) getCount() int {
fwg.Lock()
defer fwg.Unlock()
return fwg.count
}
10 changes: 5 additions & 5 deletions pkg/utils/syncutil/flexible_wait_group_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 TiKV Project Authors.
// Copyright 2023 TiKV Project Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestNegativeDelta(t *testing.T) {
fwg.Done()
}()
fwg.Wait()
require.Equal(0, fwg.count)
require.Equal(0, fwg.getCount())
}

// TestMultipleWait tests the case where Wait is called multiple times concurrently.
Expand All @@ -108,7 +108,7 @@ func TestMultipleWait(t *testing.T) {
}()
<-done
<-done
require.Equal(0, fwg.count)
require.Equal(0, fwg.getCount())
}

// TestAddAfterWaitFinished tests the case where Add is called after Wait has finished.
Expand All @@ -126,7 +126,7 @@ func TestAddAfterWaitFinished(t *testing.T) {
}()
<-done
fwg.Add(1)
require.Equal(1, fwg.count)
require.Equal(1, fwg.getCount())
fwg.Done()
require.Equal(0, fwg.count)
require.Equal(0, fwg.getCount())
}

0 comments on commit 7ced8f5

Please sign in to comment.