Skip to content

Commit

Permalink
fix(localstorage): test suite needs to allow closing storage
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Oct 28, 2024
1 parent a43e931 commit ca1f69f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/memstorage/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type SummarizedEvents struct {
}
}

func (str *MemStorage) Close() error { return nil }

func (str *MemStorage) Query(ctx context.Context, q *typesv1.LogQuery) (<-chan localstorage.Cursor, error) {
if q.To != nil && q.From.AsTime().After(q.To.AsTime()) {
return nil, fmt.Errorf("invalid query, `to` is before `from`")
Expand Down
1 change: 1 addition & 0 deletions pkg/localstorage/queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Storage interface {
Queryable
SinkFor(ctx context.Context, machineID, sessionID int64) (_ sink.Sink, heartbeatIn time.Duration, _ error)
Heartbeat(ctx context.Context, machineID, sessionID int64) (time.Duration, error)
Close() error
}

type Queryable interface {
Expand Down
7 changes: 4 additions & 3 deletions pkg/localstorage/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ func RunTest(t *testing.T, constructor func(t *testing.T) Storage) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

mem := constructor(t)
db := constructor(t)
defer db.Close()

for _, leg := range tt.input {
snk, _, err := mem.SinkFor(ctx, leg.MachineId, leg.SessionId)
snk, _, err := db.SinkFor(ctx, leg.MachineId, leg.SessionId)
require.NoError(t, err)
for _, ev := range leg.Logs {
err = snk.Receive(ctx, ev)
Expand All @@ -201,7 +202,7 @@ func RunTest(t *testing.T, constructor func(t *testing.T) Storage) {
defer cancel()
}
now := time.Now()
cursors, err := mem.Query(queryctx, tt.q)
cursors, err := db.Query(queryctx, tt.q)
require.NoError(t, err)
got := drainCursors(t, queryctx, cursors)

Expand Down

0 comments on commit ca1f69f

Please sign in to comment.