diff --git a/lib/tracker/frame-list_test.go b/lib/tracker/frame-list_test.go index b1ea1545..490e6254 100644 --- a/lib/tracker/frame-list_test.go +++ b/lib/tracker/frame-list_test.go @@ -11,13 +11,13 @@ func TestStackPushPopSingle(t *testing.T) { frame := &mode_s.Frame{} - if 0 != fl.Len() { + if fl.Len() != 0 { t.Errorf("stack should be empty") } fl.Push(frame) - if c := fl.Len(); 1 != c { + if c := fl.Len(); c != 1 { t.Errorf("incorrect length after push. expected 1, got %d", c) } @@ -26,7 +26,7 @@ func TestStackPushPopSingle(t *testing.T) { t.Errorf("Failed to get the correct frame from the stack") } - if c := fl.Len(); 0 != c { + if c := fl.Len(); c != 0 { t.Errorf("incorrect length after push. expected 0, got %d", c) } } @@ -41,12 +41,12 @@ func TestStackPushPopMultiple(t *testing.T) { originals[i] = mode_s.NewFrame("8E7C7F0D581176D7BB8D48CD7714", time.Now()) fl.Push(originals[i]) - max := i + 1 + maxItems := i + 1 if i >= numItems { - max = 10 + maxItems = 10 } - if max != fl.Len() { - t.Errorf("incorrect number of items in stack expected %d != len %d", max, fl.Len()) + if maxItems != fl.Len() { + t.Errorf("incorrect number of items in stack expected %d != len %d", maxItems, fl.Len()) } } @@ -62,16 +62,28 @@ func TestStackPushPopMultiple(t *testing.T) { t.Errorf("Incorrect item fetched from stack pop %d != %d", item.TimeStamp().UnixNano(), originals[i].TimeStamp().UnixNano()) } } - if c := fl.Len(); 0 != c { + if c := fl.Len(); c != 0 { t.Errorf("incorrect length after push. expected 0, got %d", c) } - //empty pop + // empty pop if nil != fl.Pop() { t.Errorf("pop'd something off an empty queue") } } +func TestLossyFrameList_RangeEmpty(t *testing.T) { + lfl := newLossyFrameList(10) + n := 0 + lfl.Range(func(f *mode_s.Frame) bool { + n++ + return true + }) + if n != 0 { + t.Error("lossyFrameList should be empty to start with") + } +} + func BenchmarkLossyFrameList_Push(b *testing.B) { fl := newLossyFrameList(10) frame := mode_s.NewFrame("8E7C7F0D581176D7BB8D48CD7714", time.Now()) diff --git a/lib/tracker/plane.go b/lib/tracker/plane.go index 0fe77c69..60cedcc0 100644 --- a/lib/tracker/plane.go +++ b/lib/tracker/plane.go @@ -789,21 +789,23 @@ func (p *Plane) addLatLong(lat, lon float64, ts time.Time, velocityCheck bool) ( Floats64("This Lat/Lon", []float64{lat, lon}). Msg("A Frame Too Far") - var lastTS int64 - p.recentFrames.Range(func(f *mode_s.Frame) bool { - if 0 == lastTS { + if p.tracker.log.Debug().Enabled() { + var lastTS int64 + p.recentFrames.Range(func(f *mode_s.Frame) bool { + if lastTS == 0 { + lastTS = f.TimeStamp().UnixNano() + } + p.tracker.log.Error(). + Str("ICAO", f.IcaoStr()). + Time("received", f.TimeStamp()). + Int64("unix nano", f.TimeStamp().UnixNano()). + Str("Frame", f.RawString()). + Int64("Time Diff ms", (lastTS-f.TimeStamp().UnixNano())/1e6). + Msg("Frames Leading to Broken Track") lastTS = f.TimeStamp().UnixNano() - } - p.tracker.log.Error(). - Str("ICAO", f.IcaoStr()). - Time("received", f.TimeStamp()). - Int64("unix nano", f.TimeStamp().UnixNano()). - Str("Frame", f.RawString()). - Int64("Time Diff ms", (lastTS-f.TimeStamp().UnixNano())/1e6). - Msg("Frames Leading to Broken Track") - lastTS = f.TimeStamp().UnixNano() - return true - }) + return true + }) + } return } }