Skip to content

Commit a7ba846

Browse files
committed
Bump mocktime to v1.1.0 and fix synchronization issue in cache test.
1 parent 6ba9600 commit a7ba846

File tree

4 files changed

+11
-27
lines changed

4 files changed

+11
-27
lines changed

cache/cache.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import (
88
"github.com/nitroshare/golist"
99
)
1010

11-
// This channel is used by the testing suite for synchronization; it is
12-
// normally set to nil and otherwise has no effect on the package
13-
var chanTest chan any
14-
1511
type recordEntry struct {
1612
record *Record
1713
triggers *golist.List[time.Time]
@@ -34,17 +30,11 @@ func (c *Cache) run() {
3430
for {
3531
select {
3632
case <-c.nextTrigger():
37-
if chanTest != nil {
38-
chanTest <- nil
39-
}
4033
case r, ok := <-c.chanAdd:
4134
if !ok {
4235
return
4336
}
4437
c.add(r)
45-
if chanTest != nil {
46-
chanTest <- nil
47-
}
4838
}
4939
}
5040
}

cache/cache_test.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ package cache
22

33
import (
44
"testing"
5-
"time"
65

76
"github.com/nitroshare/mocktime"
87
)
98

10-
func init() {
11-
chanTest = make(chan any)
12-
}
13-
149
func TestRecordQueryExpiry(t *testing.T) {
1510
mocktime.Mock()
1611
defer mocktime.Unmock()
@@ -22,14 +17,13 @@ func TestRecordQueryExpiry(t *testing.T) {
2217
ChanExpired: chanExpired,
2318
})
2419
)
25-
r := &Record{
26-
TTL: 10,
20+
c.Add(&Record{
21+
TTL: 1,
22+
})
23+
for range 4 {
24+
mocktime.AdvanceToAfter()
25+
<-chanQuery
2726
}
28-
c.Add(r)
29-
mocktime.Advance(6 * time.Second)
30-
<-chanTest
31-
<-chanQuery
32-
mocktime.Advance(5 * time.Second)
33-
<-chanTest
27+
mocktime.AdvanceToAfter()
3428
<-chanExpired
3529
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ go 1.23.0
44

55
require (
66
github.com/miekg/dns v1.1.67
7-
github.com/nitroshare/mocktime v1.0.5
7+
github.com/nitroshare/golist v1.0.2
8+
github.com/nitroshare/mocktime v1.1.0
89
)
910

1011
require (
11-
github.com/nitroshare/golist v1.0.2 // indirect
1212
golang.org/x/mod v0.24.0 // indirect
1313
golang.org/x/net v0.40.0 // indirect
1414
golang.org/x/sync v0.14.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/nitroshare/compare v1.0.1 h1:vnlCEflz1O/6hZ+/HYwaBJB0OG4xRX2eIX0lVb1W
66
github.com/nitroshare/compare v1.0.1/go.mod h1:YnsFVZura0jowTncpTZtdciU1qdP3nthsqLAc5ql5F4=
77
github.com/nitroshare/golist v1.0.2 h1:GKwazg8PqSp8hiwWTsTFzRu86haDCcIZruVb2dqaXeQ=
88
github.com/nitroshare/golist v1.0.2/go.mod h1:jJhoY4v2aiz2WYKSYE6/9OxnAEm2Nz6I4ZKmM/oDJgU=
9-
github.com/nitroshare/mocktime v1.0.5 h1:ZGDTqCMDgL4u7dkRe26uMjHDaUo2AJBGMTE8Bnx9KPM=
10-
github.com/nitroshare/mocktime v1.0.5/go.mod h1:c6uMhYj4nXSlAspYJBIzHyV4Tm0fRTgZBRI0eZ43/ME=
9+
github.com/nitroshare/mocktime v1.1.0 h1:PIk00wDw4hNF8M1/Rpr3FidtjeZ39TNl6aP//k3OevQ=
10+
github.com/nitroshare/mocktime v1.1.0/go.mod h1:c6uMhYj4nXSlAspYJBIzHyV4Tm0fRTgZBRI0eZ43/ME=
1111
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
1212
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
1313
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=

0 commit comments

Comments
 (0)