Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(localstorage): test suite needs to allow closing storage #105

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading