Added WaitForValue test function
parent
f6a36f9028
commit
3f7d452954
|
|
@ -9,13 +9,30 @@ import (
|
|||
type graph_tester testing.T
|
||||
const listner_timeout = 50 * time.Millisecond
|
||||
|
||||
func (t * graph_tester) CheckForValue(listener chan GraphSignal, str string) {
|
||||
func (t * graph_tester) WaitForValue(listener chan GraphSignal, signal_type string, timeout time.Duration, str string) GraphSignal {
|
||||
timeout_channel := time.After(timeout)
|
||||
for true {
|
||||
select {
|
||||
case signal := <- listener:
|
||||
if signal.Type() == signal_type {
|
||||
return signal
|
||||
}
|
||||
case <-timeout_channel:
|
||||
t.Fatal(str)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t * graph_tester) CheckForValue(listener chan GraphSignal, str string) GraphSignal {
|
||||
timeout := time.After(listner_timeout)
|
||||
select {
|
||||
case <- listener:
|
||||
return
|
||||
case signal := <- listener:
|
||||
return signal
|
||||
case <-timeout:
|
||||
t.Fatal(str)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
32
vex_test.go
32
vex_test.go
|
|
@ -149,37 +149,31 @@ func TestNewMatch(t *testing.T) {
|
|||
}()
|
||||
|
||||
go func(match_c chan GraphSignal) {
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after starting 1")
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after starting 2")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after starting 3")
|
||||
(*graph_tester)(t).WaitForValue(match_c, "event_start", 1*time.Second, "no event_start")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after starting")
|
||||
SendUpdate(arena, NewSignal(nil, "queue_autonomous"))
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after queueing autonomous 1")
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after queueing autonomous 2")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after queueing autonomous 3")
|
||||
(*graph_tester)(t).WaitForValue(match_c, "autonomous_queued", 1*time.Second, "no autonomous_queued")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after queueing autonomous")
|
||||
auton_signal := NewSignal(nil, "start_autonomous")
|
||||
auton_signal.time = time.Now()
|
||||
SendUpdate(arena, auton_signal)
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after starting autonomous 1")
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after starting autonomous 2")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after starting autonomous 3")
|
||||
(*graph_tester)(t).WaitForValue(match_c, "autonomous_running", 1*time.Second, "no autonomous_running")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after starting autonomous")
|
||||
time.Sleep(TEMP_AUTON_TIME)
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after ending autonomous 1")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after ending autonomous 2")
|
||||
(*graph_tester)(t).WaitForValue(match_c, "autonomous_done", 6*time.Second, "no autonomous_done")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after ending autonomous")
|
||||
SendUpdate(arena, NewSignal(nil, "queue_driver"))
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after queueing driver 1")
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after queueing driver 2")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after queueing driver 3")
|
||||
(*graph_tester)(t).WaitForValue(match_c, "driver_queued", 1*time.Second, "no driver_queued")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after queueing driver")
|
||||
driver_signal := NewSignal(nil, "start_driver")
|
||||
driver_signal.time = time.Now()
|
||||
SendUpdate(arena, driver_signal)
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after starting driver 1")
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after starting driver 2")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after starting driver 3")
|
||||
(*graph_tester)(t).WaitForValue(match_c, "driver_running", 1*time.Second, "no driver_running")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after starting driver")
|
||||
time.Sleep(TEMP_DRIVE_TIME)
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after game done 1")
|
||||
(*graph_tester)(t).CheckForValue(match_c, "no update to match after game done 2")
|
||||
(*graph_tester)(t).WaitForValue(match_c, "driver_done", 1*time.Second, "no driver_done")
|
||||
(*graph_tester)(t).CheckForNone(match_c, "update to match after game done 3")
|
||||
}(match_c)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue