Skip to content

Commit

Permalink
small tweaks and testing for lossyFrameList
Browse files Browse the repository at this point in the history
  • Loading branch information
bluntelk committed Dec 1, 2023
1 parent aa57692 commit 3777ea6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
30 changes: 21 additions & 9 deletions lib/tracker/frame-list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}
}
Expand All @@ -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())
}
}

Expand All @@ -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())
Expand Down
30 changes: 16 additions & 14 deletions lib/tracker/plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 3777ea6

Please sign in to comment.