Skip to content

Commit

Permalink
Merge pull request #534 from OdyseeTeam/fix-olapdb-error
Browse files Browse the repository at this point in the history
Fix intermittent olapdb test failures
  • Loading branch information
anbsky authored Jan 7, 2025
2 parents 15a2b2a + d106429 commit 161c172
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions apps/watchman/olapdb/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package olapdb

import (
"fmt"
"sort"
"testing"
"time"

Expand Down Expand Up @@ -38,20 +39,36 @@ func (s *batchWriterSuite) TestBatch() {
time.Sleep(3 * time.Second)
bw.Stop()

var (
url string
duration int32
)
rows, err := conn.Query(fmt.Sprintf("SELECT URL, Duration from %s.playback ORDER BY Timestamp DESC", database))
s.Require().NoError(err)
defer rows.Close()
type duration struct {
URL string
Duration int32
}
retDurations := []duration{}
for i, r := range reports {
n := rows.Next()
s.Require().True(n, "only %v rows in db, expected %v", i, len(reports))
err = rows.Scan(&url, &duration)
d := duration{}
err = rows.Scan(&d.URL, &d.Duration)
s.Require().NoError(err)
s.Equal(r.URL, url)
s.Equal(r.Duration, duration)
retDurations = append(retDurations, d)
s.Equal(r.URL, d.URL)
s.Equal(r.Duration, d.Duration)
}
s.False(rows.Next())

sort.Slice(retDurations, func(i, j int) bool {
return retDurations[i].Duration < retDurations[j].Duration
})
sort.Slice(reports, func(i, j int) bool {
return reports[i].Duration < reports[j].Duration
})

s.Equal(len(reports), len(retDurations))
for i := range reports {
s.Equal(reports[i].URL, retDurations[i].URL)
s.Equal(reports[i].Duration, retDurations[i].Duration)
}
}

0 comments on commit 161c172

Please sign in to comment.