Skip to content

Commit e552095

Browse files
committed
improve TestProxyManager_StartupHooks
1 parent aeaa4ec commit e552095

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

proxy/proxymanager_test.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ hooks:
847847
- model1
848848
- model2
849849
groups:
850-
test:
850+
preloadTestGroup:
851851
swap: false
852852
members:
853853
- model1
@@ -865,24 +865,30 @@ models:
865865
return
866866
}
867867

868-
// Create the proxy which should trigger preloading
869-
proxy := New(config)
870-
defer proxy.StopProcesses(StopWaitForInflightRequest)
868+
preloadChan := make(chan ModelPreloadedEvent, 2) // buffer for 2 expected events
871869

872-
var w sync.WaitGroup
873-
w.Add(2)
874-
875-
event.On(func(e ModelPreloadedEvent) {
876-
w.Done()
870+
unsub := event.On(func(e ModelPreloadedEvent) {
871+
preloadChan <- e
877872
})
878873

879-
w.Wait()
874+
defer unsub()
875+
876+
// Create the proxy which should trigger preloading
877+
proxy := New(config)
878+
defer proxy.StopProcesses(StopWaitForInflightRequest)
880879

880+
for i := 0; i < 2; i++ {
881+
select {
882+
case <-preloadChan:
883+
case <-time.After(5 * time.Second):
884+
t.Fatal("timed out waiting for models to preload")
885+
}
886+
}
881887
// make sure they are both loaded
882-
_, foundGroup := proxy.processGroups["test"]
883-
if !assert.True(t, foundGroup, "test group should exist") {
888+
_, foundGroup := proxy.processGroups["preloadTestGroup"]
889+
if !assert.True(t, foundGroup, "preloadTestGroup should exist") {
884890
return
885891
}
886-
assert.Equal(t, StateReady, proxy.processGroups["test"].processes["model1"].CurrentState())
887-
assert.Equal(t, StateReady, proxy.processGroups["test"].processes["model2"].CurrentState())
892+
assert.Equal(t, StateReady, proxy.processGroups["preloadTestGroup"].processes["model1"].CurrentState())
893+
assert.Equal(t, StateReady, proxy.processGroups["preloadTestGroup"].processes["model2"].CurrentState())
888894
}

0 commit comments

Comments
 (0)