* fix webconn close semantics

Avoid race conditions in WebConn on shutdown by closing channels to guarantee all readers are notified. Wrap this with sync.Once to avoid closing the channel more than once.

* web_hub_test.go

* webhub: fix race condition on shutdown

Ensure that if the webhub shuts down in the process of sending, the caller unblocks given that the webhub will no longer consume incoming events.

* panic if app shutdown takes >30 seconds

* simplify WebConn::Pump channel semantics too
Этот коммит содержится в:
Jesse Hallam
2018-11-22 04:53:44 -05:00
коммит произвёл Jesús Espino
родитель 1271908182
Коммит f8ffd68060
5 изменённых файлов: 108 добавлений и 14 удалений

Просмотреть файл

@@ -179,10 +179,26 @@ func SetupConfig(updateConfig func(cfg *model.Config)) *TestHelper {
return setupTestHelper(false, updateConfig)
}
func (me *TestHelper) ShutdownApp() {
done := make(chan bool)
go func() {
me.App.Shutdown()
close(done)
}()
select {
case <-done:
case <-time.After(30 * time.Second):
// panic instead of t.Fatal to terminate all tests in this package, otherwise the
// still running App could spuriously fail subsequent tests.
panic("failed to shutdown App within 30 seconds")
}
}
func (me *TestHelper) TearDown() {
utils.DisableDebugLogForTest()
me.App.Shutdown()
me.ShutdownApp()
os.Remove(me.tempConfigPath)
utils.EnableDebugLogForTest()