Skip to content

Commit

Permalink
test(general): repodiag context cancellation test
Browse files Browse the repository at this point in the history
  • Loading branch information
julio-lopez committed Oct 22, 2024
1 parent c055ed1 commit 1c90b28
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/repodiag/log_manager_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package repodiag_test

import (
"context"
"crypto/rand"
"encoding/hex"
"strings"
Expand Down Expand Up @@ -84,6 +85,30 @@ func TestLogManager_NotEnabled(t *testing.T) {
require.Empty(t, d)
}

func TestLogManager_CancelledContext(t *testing.T) {
d := blobtesting.DataMap{}
st := blobtesting.NewMapStorage(d, nil, nil)
w := repodiag.NewWriter(st, newStaticCrypter(t))
ctx := testlogging.Context(t)
cctx, cancel := context.WithCancel(ctx)
lm := repodiag.NewLogManager(cctx, w)

// cancel context, logs should still be written
cancel()

lm.Enable()
l := lm.NewLogger()
l.Info("hello")

require.Empty(t, d)

l.Sync()
w.Wait(ctx)

// make sure log messages are written
require.Len(t, d, 1)
}

func TestLogManager_Null(t *testing.T) {
var lm *repodiag.LogManager

Expand Down

0 comments on commit 1c90b28

Please sign in to comment.