simplified and fixed flaky test
This commit is contained in:
@@ -38,11 +38,8 @@ func TestNotifyWatcher_SettingsUpdate(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancelCtx := context.WithTimeout(context.Background(), 1*time.Second)
|
timeout := time.After(3 * time.Second)
|
||||||
defer cancelCtx()
|
done := make(chan struct{})
|
||||||
|
|
||||||
sem := semaphore.NewWeighted(1)
|
|
||||||
sem.Acquire(ctx, 1)
|
|
||||||
|
|
||||||
app1.OnSettingsReload().BindFunc(func(e *core.SettingsReloadEvent) error {
|
app1.OnSettingsReload().BindFunc(func(e *core.SettingsReloadEvent) error {
|
||||||
testEvents.SetFunc(app1, func(old int) int {
|
testEvents.SetFunc(app1, func(old int) int {
|
||||||
@@ -53,7 +50,9 @@ func TestNotifyWatcher_SettingsUpdate(t *testing.T) {
|
|||||||
|
|
||||||
app2.OnSettingsReload().BindFunc(func(e *core.SettingsReloadEvent) error {
|
app2.OnSettingsReload().BindFunc(func(e *core.SettingsReloadEvent) error {
|
||||||
testEvents.SetFunc(app2, func(old int) int {
|
testEvents.SetFunc(app2, func(old int) int {
|
||||||
sem.Release(1)
|
defer func() {
|
||||||
|
done <- struct{}{}
|
||||||
|
}()
|
||||||
|
|
||||||
return old + 1
|
return old + 1
|
||||||
})
|
})
|
||||||
@@ -66,8 +65,13 @@ func TestNotifyWatcher_SettingsUpdate(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// block until released or timeouted
|
// wait for the event
|
||||||
sem.Acquire(ctx, 1)
|
select {
|
||||||
|
case <-timeout:
|
||||||
|
t.Fatal("app2 reload event timeout")
|
||||||
|
case <-done:
|
||||||
|
// ready
|
||||||
|
}
|
||||||
|
|
||||||
if app1Total := testEvents.Get(app1); app1Total != 1 {
|
if app1Total := testEvents.Get(app1); app1Total != 1 {
|
||||||
t.Fatalf("Expected 1 app1 event, got %d", app1Total)
|
t.Fatalf("Expected 1 app1 event, got %d", app1Total)
|
||||||
|
|||||||
Reference in New Issue
Block a user