@ -33,6 +33,14 @@ func TestRadioMonitor(t *testing.T) {
func ( _ * testTime , _ * radioMonitor ) { } ,
func ( _ * testTime , _ * radioMonitor ) { } ,
0 ,
0 ,
} ,
} ,
{
"active less than init stall period" ,
func ( tt * testTime , rm * radioMonitor ) {
rm . active ( )
tt . Add ( 1 * time . Second )
} ,
0 , // radio on, but not long enough to report data
} ,
{
{
"active, 10 sec idle" ,
"active, 10 sec idle" ,
func ( tt * testTime , rm * radioMonitor ) {
func ( tt * testTime , rm * radioMonitor ) {
@ -42,13 +50,13 @@ func TestRadioMonitor(t *testing.T) {
50 , // radio on 5 seconds of 10 seconds
50 , // radio on 5 seconds of 10 seconds
} ,
} ,
{
{
"active, spanning t wo seconds",
"active, spanning t hree seconds",
func ( tt * testTime , rm * radioMonitor ) {
func ( tt * testTime , rm * radioMonitor ) {
rm . active ( )
rm . active ( )
tt . Add ( 1 100 * time . Millisecond )
tt . Add ( 2 100 * time . Millisecond )
rm . active ( )
rm . active ( )
} ,
} ,
100 , // radio on for 2 seconds
100 , // radio on for 3 seconds
} ,
} ,
{
{
"400 iterations: 2 sec active, 1 min idle" ,
"400 iterations: 2 sec active, 1 min idle" ,
@ -66,13 +74,17 @@ func TestRadioMonitor(t *testing.T) {
{
{
"activity at end of time window" ,
"activity at end of time window" ,
func ( tt * testTime , rm * radioMonitor ) {
func ( tt * testTime , rm * radioMonitor ) {
tt . Add ( 1 * time . Second )
tt . Add ( 3 * time . Second )
rm . active ( )
rm . active ( )
} ,
} ,
50 ,
2 5,
} ,
} ,
}
}
oldStallPeriod := initStallPeriod
initStallPeriod = 3
t . Cleanup ( func ( ) { initStallPeriod = oldStallPeriod } )
for _ , tt := range tests {
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
t . Run ( tt . name , func ( t * testing . T ) {
tm := & testTime { time . Date ( 2021 , 1 , 1 , 0 , 0 , 0 , 0 , time . UTC ) }
tm := & testTime { time . Date ( 2021 , 1 , 1 , 0 , 0 , 0 , 0 , time . UTC ) }