Skip to content

Commit

Permalink
close(process.doneCh)
Browse files Browse the repository at this point in the history
  • Loading branch information
cj123 committed Oct 25, 2019
1 parent e887c4c commit 83d6890
Showing 1 changed file with 0 additions and 127 deletions.
127 changes: 0 additions & 127 deletions race_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,133 +653,6 @@ func TestRaceControl_OnNewSession(t *testing.T) {
}
}
})

t.Run("Two separate event progressions", func(t *testing.T) {
process := dummyServerProcess{doneCh: make(chan struct{})}
raceControl := NewRaceControl(NilBroadcaster{}, nilTrackData{}, process)

if err := raceControl.OnVersion(udp.Version(4)); err != nil {
t.Error(err)
return
}

// new session
err := raceControl.OnNewSession(udp.SessionInfo{
Version: 4,
SessionIndex: 0,
CurrentSessionIndex: 0,
SessionCount: 3,
ServerName: "Test Server",
Track: "ks_laguna_seca",
TrackConfig: "",
Name: "Test Practice Session",
Type: udp.SessionTypePractice,
Time: 10,
Laps: 0,
WaitTime: 120,
AmbientTemp: 12,
RoadTemp: 16,
WeatherGraphics: "01_clear",
ElapsedMilliseconds: 10,

EventType: udp.EventNewSession,
})

if err != nil {
t.Error(err)
return
}

time.Sleep(time.Millisecond * 10)

// stop the session info ticker
defer raceControl.sessionInfoCfn()

// join and load all drivers
for _, entrant := range drivers {
if err := raceControl.OnClientConnect(entrant); err != nil {
t.Error(err)
return
}

if err := raceControl.OnClientLoaded(udp.ClientLoaded(entrant.CarID)); err != nil {
t.Error(err)
return
}
}

if raceControl.ConnectedDrivers.Len() != len(drivers) || raceControl.DisconnectedDrivers.Len() > 0 {
t.Error("Incorrect driver listings")
return
}

// do some laps for each entrant
for i := 0; i < 100; i++ {
driver := drivers[i%len(drivers)]

err := raceControl.OnLapCompleted(udp.LapCompleted{
CarID: driver.CarID,
LapTime: uint32(rand.Intn(1000000)),
Cuts: 0,
})

if err != nil {
t.Error(err)
return
}
}

// disconnect one of the drivers
disconnectedDriver := drivers[len(drivers)-1]
disconnectedDriver.EventType = udp.EventConnectionClosed
err = raceControl.OnClientDisconnect(disconnectedDriver)

if err != nil {
t.Error(err)
return
}

err = raceControl.OnEndSession(udp.EndSession("FILE.json"))

if err != nil {
t.Error(err)
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,
SessionIndex: 0,
CurrentSessionIndex: 0,
SessionCount: 1,
ServerName: "Test Server",
Track: "spa",
TrackConfig: "",
Name: "Test Practice Session",
Type: udp.SessionTypeQualifying,
Time: 10,
Laps: 0,
WaitTime: 120,
AmbientTemp: 12,
RoadTemp: 16,
WeatherGraphics: "02_cloudy",
ElapsedMilliseconds: 10,

EventType: udp.EventNewSession,
})

if err != nil {
t.Error(err)
return
}

if raceControl.ConnectedDrivers.Len() != 0 || raceControl.DisconnectedDrivers.Len() != 0 {
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
}
})
}

func TestRaceControl_OnCarUpdate(t *testing.T) {
Expand Down

0 comments on commit 83d6890

Please sign in to comment.