Skip to content

Commit

Permalink
Merge pull request #592 from cj123/live-timings-loop-reconnect
Browse files Browse the repository at this point in the history
fix live timings disconnect on event loop
  • Loading branch information
cj123 authored Oct 25, 2019
2 parents 646c17c + 6936d04 commit c3e3dbe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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

---

Expand Down
13 changes: 9 additions & 4 deletions championship_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ var TestEntryList = EntryList{
},
}

type dummyServerProcess struct{}
type dummyServerProcess struct {
doneCh chan struct{}
}

func (dummyServerProcess) Logs() string {
return ""
Expand All @@ -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
}

Expand All @@ -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 {
Expand Down
18 changes: 3 additions & 15 deletions race_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
7 changes: 5 additions & 2 deletions race_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
})
Expand Down

0 comments on commit c3e3dbe

Please sign in to comment.