Skip to content

Commit 4d60767

Browse files
committed
add test
1 parent 5c7ef22 commit 4d60767

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

e2e/test/lqvacuumer/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
max-retry = 0 # avoid waiting for retries to speed up test
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package nxdomain
2+
3+
import (
4+
_ "embed"
5+
"os"
6+
"strings"
7+
"sync"
8+
"testing"
9+
"time"
10+
11+
"github.com/internetarchive/Zeno/e2e"
12+
"github.com/internetarchive/Zeno/internal/pkg/source/lq"
13+
)
14+
15+
type recordMatcher struct {
16+
vacuumedSuccess bool
17+
unexpectedError bool
18+
}
19+
20+
func (rm *recordMatcher) Match(record map[string]string) {
21+
if record["level"] == "INFO" && record["msg"] == "vacuuming complete" {
22+
rm.vacuumedSuccess = true
23+
}
24+
if record["level"] == "ERROR" {
25+
if strings.Contains(record["err"], "failed to resolve DNS") {
26+
} else {
27+
rm.unexpectedError = true
28+
}
29+
}
30+
}
31+
32+
func (rm *recordMatcher) Assert(t *testing.T) {
33+
if rm.unexpectedError {
34+
t.Error("An unexpected error was logged during the test")
35+
}
36+
}
37+
38+
func (rm *recordMatcher) ShouldStop() bool {
39+
return rm.vacuumedSuccess || rm.unexpectedError
40+
}
41+
42+
func Test_LQ_vacuumer(t *testing.T) {
43+
os.RemoveAll("jobs")
44+
45+
rm := &recordMatcher{}
46+
wg := &sync.WaitGroup{}
47+
shouldStopCh := make(chan struct{})
48+
wg.Add(2)
49+
50+
lq.VacuumInterval = 1 * time.Second
51+
52+
go e2e.StartHandleLogRecord(t, wg, rm, shouldStopCh)
53+
go e2e.ExecuteCmdZenoGetURL(t, wg, []string{"http://nxdomain.nxtld/"})
54+
55+
e2e.WaitForGoroutines(t, wg, shouldStopCh)
56+
rm.Assert(t)
57+
58+
}

0 commit comments

Comments
 (0)