From 65c0c35cd6713789aa3719efc129b3a9a73a2c8a Mon Sep 17 00:00:00 2001 From: Callum Jones Date: Fri, 25 Oct 2019 16:30:50 +0100 Subject: [PATCH 1/2] fix live timings disconnect on event loop --- CHANGELOG.md | 1 + race_control.go | 18 +++--------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ea97d77f..6826bb28a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Fixes: * Fixes an issue where cars with no skins might prevent a race from starting. * Fixes an issue where Scheduled Championship Race Weekend sessions caused the calendar to error on load. * Fixes the Race Weekend "Start after previous session" checkbox not displaying correctly. +* Fixes an issue where all drivers were incorrectly disconnected from the Live Timings page when an event with multiple sessions looped v1.5.1 ------ diff --git a/race_control.go b/race_control.go index 5d862f93f..23dd8be91 100644 --- a/race_control.go +++ b/race_control.go @@ -216,27 +216,15 @@ func (rc *RaceControl) OnNewSession(sessionInfo udp.SessionInfo) error { rc.driverGUIDUpdateCounter = make(map[udp.DriverGUID]int) rc.driverGUIDUpdateCounterMutex.Unlock() - deleteCars := true - emptyCarInfo := false - - if sessionInfo.CurrentSessionIndex != 0 && oldSessionInfo.Track == sessionInfo.Track && oldSessionInfo.TrackConfig == sessionInfo.TrackConfig { - // only remove cars on the first session (avoid deleting between practice/qualify/race) - deleteCars = false - emptyCarInfo = true - } + emptyCarInfo := true if (rc.ConnectedDrivers.Len() > 0 || rc.DisconnectedDrivers.Len() > 0) && sessionInfo.Type == udp.SessionTypePractice { if oldSessionInfo.Type == sessionInfo.Type && oldSessionInfo.Track == sessionInfo.Track && oldSessionInfo.TrackConfig == sessionInfo.TrackConfig && oldSessionInfo.Name == sessionInfo.Name { - // this is a looped practice event, keep the cars - deleteCars = false + // this is a looped event, keep the cars emptyCarInfo = false } } - if deleteCars { - rc.clearAllDrivers() - } - if emptyCarInfo { _ = rc.ConnectedDrivers.Each(func(driverGUID udp.DriverGUID, driver *RaceControlDriver) error { *driver = *NewRaceControlDriver(driver.CarInfo) @@ -274,7 +262,7 @@ func (rc *RaceControl) OnNewSession(sessionInfo udp.SessionInfo) error { rc.TrackMapData = *trackMapData } - logrus.Debugf("New session detected: %s at %s (%s) [deleteCars: %t, emptyCarInfo: %t]", sessionInfo.Type.String(), sessionInfo.Track, sessionInfo.TrackConfig, deleteCars, emptyCarInfo) + logrus.Debugf("New session detected: %s at %s (%s) [emptyCarInfo: %t]", sessionInfo.Type.String(), sessionInfo.Track, sessionInfo.TrackConfig, emptyCarInfo) go rc.requestSessionInfo() From 6936d04da1ed5f62195e8169fdbdc7f934986646 Mon Sep 17 00:00:00 2001 From: Callum Jones Date: Fri, 25 Oct 2019 17:01:38 +0100 Subject: [PATCH 2/2] fix race control tests --- championship_manager_test.go | 13 +++++++++---- race_control_test.go | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/championship_manager_test.go b/championship_manager_test.go index 2aa5a1b38..b1942c54a 100644 --- a/championship_manager_test.go +++ b/championship_manager_test.go @@ -59,7 +59,9 @@ var TestEntryList = EntryList{ }, } -type dummyServerProcess struct{} +type dummyServerProcess struct { + doneCh chan struct{} +} func (dummyServerProcess) Logs() string { return "" @@ -69,7 +71,10 @@ func (dummyServerProcess) Start(cfg ServerConfig, entryList EntryList, forwardin return nil } -func (dummyServerProcess) Stop() error { +func (d dummyServerProcess) Stop() error { + if d.doneCh != nil { + d.doneCh <- struct{}{} + } return nil } @@ -92,8 +97,8 @@ func (dummyServerProcess) SendUDPMessage(message udp.Message) error { return nil } -func (dummyServerProcess) Done() <-chan struct{} { - return nil +func (d dummyServerProcess) Done() <-chan struct{} { + return d.doneCh } func (dummyServerProcess) GetServerConfig() ServerConfig { diff --git a/race_control_test.go b/race_control_test.go index 077be0ad3..2593e2717 100644 --- a/race_control_test.go +++ b/race_control_test.go @@ -655,7 +655,8 @@ func TestRaceControl_OnNewSession(t *testing.T) { }) t.Run("Two separate event progressions", func(t *testing.T) { - raceControl := NewRaceControl(NilBroadcaster{}, nilTrackData{}, dummyServerProcess{}) + process := dummyServerProcess{doneCh: make(chan struct{})} + raceControl := NewRaceControl(NilBroadcaster{}, nilTrackData{}, process) if err := raceControl.OnVersion(udp.Version(4)); err != nil { t.Error(err) @@ -745,6 +746,8 @@ func TestRaceControl_OnNewSession(t *testing.T) { return } + process.Stop() + // now go to the next session, lap times should be removed from all drivers, but all should still be connected. err = raceControl.OnNewSession(udp.SessionInfo{ Version: 4, @@ -773,7 +776,7 @@ func TestRaceControl_OnNewSession(t *testing.T) { } if raceControl.ConnectedDrivers.Len() != 0 || raceControl.DisconnectedDrivers.Len() != 0 { - t.Error("Invalid driver list lengths. Expected 0 drivers to still be in driver lists.") + t.Errorf("Invalid driver list lengths. Expected 0 drivers to still be in driver lists. (%d conn, %d disconn)", raceControl.ConnectedDrivers.Len(), raceControl.DisconnectedDrivers.Len()) return } })