This commit is contained in:
+12
-12
@@ -144,21 +144,21 @@ func TestClientWingbitsEndpoints(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamAircraft(t *testing.T) {
|
||||
func TestPollAircraft(t *testing.T) {
|
||||
c := newTestClient(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
ch := c.StreamAircraft(ctx, time.Hour)
|
||||
select {
|
||||
case u := <-ch:
|
||||
if u.Err != nil || u.Value == nil || len(u.Value.Aircraft) == 0 {
|
||||
t.Fatalf("first update bad: %v", u.Err)
|
||||
// A long interval means the iterator only yields its immediate first sample;
|
||||
// breaking out must stop polling cleanly (no goroutine, no hang).
|
||||
var got int
|
||||
for report, err := range c.PollAircraft(ctx, time.Hour, readsb.WithPosition()) {
|
||||
if err != nil || report == nil || len(report.Aircraft) == 0 {
|
||||
t.Fatalf("first poll bad: %v", err)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("no first update")
|
||||
got++
|
||||
break
|
||||
}
|
||||
cancel()
|
||||
for range ch { // channel must drain and close after cancellation
|
||||
if got != 1 {
|
||||
t.Fatalf("expected exactly one sample before break, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user