fix(go): guard realtime mysql against stale events
This commit is contained in:
@@ -182,6 +182,30 @@ func TestSnapshotWriterUpsertsRealtimeLocationWhenCoordinatesExist(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRealtimeUpsertsDoNotOverwriteWithOlderEventTime(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
table string
|
||||
query string
|
||||
}{
|
||||
{name: "snapshot", table: "vehicle_realtime_snapshot", query: upsertRealtimeSnapshotSQL},
|
||||
{name: "location", table: "vehicle_realtime_location", query: upsertRealtimeLocationSQL},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
guard := "VALUES(event_time) IS NOT NULL AND (" + tc.table + ".event_time IS NULL OR VALUES(event_time) >= " + tc.table + ".event_time)"
|
||||
if !strings.Contains(tc.query, guard) {
|
||||
t.Fatalf("upsert should guard realtime state by event_time, missing %q in:\n%s", guard, tc.query)
|
||||
}
|
||||
if strings.Contains(tc.query, "event_time = VALUES(event_time)") {
|
||||
t.Fatalf("upsert should not unconditionally replace event_time:\n%s", tc.query)
|
||||
}
|
||||
if strings.Contains(tc.query, "event_id = VALUES(event_id)") {
|
||||
t.Fatalf("upsert should not unconditionally replace event_id:\n%s", tc.query)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSnapshotWriterBackfillsPlateFromBindingByVIN(t *testing.T) {
|
||||
exec := &recordingSnapshotExec{}
|
||||
resolver := &recordingPlateResolver{plate: "沪A12345"}
|
||||
|
||||
Reference in New Issue
Block a user