Commit 2824b3b2 authored by Francis Li's avatar Francis Li Committed by GitHub

[conductor] Fix test race condition (#13314)

* Fix conductor test race condition

* update

* Address shell ci check

* rerun CI for non-related issue
parent 4c88138e
...@@ -381,9 +381,7 @@ func (oc *OpConductor) Start(ctx context.Context) error { ...@@ -381,9 +381,7 @@ func (oc *OpConductor) Start(ctx context.Context) error {
oc.log.Info("OpConductor started") oc.log.Info("OpConductor started")
// queue an action in case sequencer is not in the desired state. // queue an action in case sequencer is not in the desired state.
oc.prevState = NewState(oc.leader.Load(), oc.healthy.Load(), oc.seqActive.Load()) oc.prevState = NewState(oc.leader.Load(), oc.healthy.Load(), oc.seqActive.Load())
// Immediately queue an action. This is made blocking to ensure that start is not oc.queueAction()
// considered complete until the first action is executed.
oc.actionCh <- struct{}{}
return nil return nil
} }
......
...@@ -106,7 +106,7 @@ func (s *OpConductorTestSuite) SetupSuite() { ...@@ -106,7 +106,7 @@ func (s *OpConductorTestSuite) SetupSuite() {
s.metrics = &metrics.NoopMetricsImpl{} s.metrics = &metrics.NoopMetricsImpl{}
s.cfg = mockConfig(s.T()) s.cfg = mockConfig(s.T())
s.version = "v0.0.1" s.version = "v0.0.1"
s.next = make(chan struct{}, 1) s.next = make(chan struct{})
} }
func (s *OpConductorTestSuite) SetupTest() { func (s *OpConductorTestSuite) SetupTest() {
...@@ -129,7 +129,8 @@ func (s *OpConductorTestSuite) SetupTest() { ...@@ -129,7 +129,8 @@ func (s *OpConductorTestSuite) SetupTest() {
s.conductor.leaderUpdateCh = s.leaderUpdateCh s.conductor.leaderUpdateCh = s.leaderUpdateCh
s.err = errors.New("error") s.err = errors.New("error")
s.syncEnabled = false // default to no sync, turn it on by calling s.enableSynchronization() s.syncEnabled = false // default to no sync, turn it on by calling s.enableSynchronization()
s.wg = sync.WaitGroup{} // create new wg for every test in case last test didn't finish the action loop during shutdown.
} }
func (s *OpConductorTestSuite) TearDownTest() { func (s *OpConductorTestSuite) TearDownTest() {
...@@ -876,6 +877,5 @@ func (s *OpConductorTestSuite) TestHandleInitError() { ...@@ -876,6 +877,5 @@ func (s *OpConductorTestSuite) TestHandleInitError() {
} }
func TestControlLoop(t *testing.T) { func TestControlLoop(t *testing.T) {
t.Skipf("Skipping test, it's flaky and needs to be fixed")
suite.Run(t, new(OpConductorTestSuite)) suite.Run(t, new(OpConductorTestSuite))
} }
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
set -e set -e
for i in {1..100}; do for i in {1..1000}; do
echo "=======================" echo "======================="
echo "Running iteration $i" echo "Running iteration $i"
if ! gotestsum -- -run 'TestControlLoop' ./... --count=1 --timeout=5s -race; then
if ! go test -v ./conductor/... -race -count=1; then
echo "Test failed" echo "Test failed"
exit 1 exit 1
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment