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

Add standing unit test for #4 #5

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
16 changes: 11 additions & 5 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,30 +338,36 @@ func TestNotifyMetadata(t *testing.T) {
// loop. The loop should abort and not call the remaining subscribers. It should instead restart and run through each
// subscriber with the updated value.
func TestWatchableValueUpdateCancel(t *testing.T) {
prefix := ads.XDSTPScheme + "/" + diderot.TypeOf[*Timestamp]().TrimmedURL() + "/foo/"

c := newCache()

r1 := newResource(name1, "0")
r1 := newResource(prefix+name1, "0")

var r1Wg, r2Wg sync.WaitGroup
r1Wg.Add(1)
r2Wg.Add(2)
r2Wg.Add(3)
notify := func(name string, r *ads.Resource[*Timestamp], _ ads.SubscriptionMetadata) {
// r is nil during the initial invocation of notify since the resource does not yet exist.
if r == nil {
return
}

if r == r1 {
c.Set(name1, "1", Now(), noTime)
c.Set(prefix+name1, "1", Now(), noTime)
// if notify is invoked with r1 more than once, this will panic
r1Wg.Done()
} else {
r2Wg.Done()
}
}

c.Subscribe(name1, testutils.NewSubscriptionHandler(notify))
c.Subscribe(name1, testutils.NewSubscriptionHandler(notify))
c.Subscribe(prefix+name1, testutils.NewSubscriptionHandler(notify))
// Use a glob and wildcard subscriptions, this flexes the code path in watchableValue that iterates
// through the various subscriber sets, and had a bug where breaking before exhausting the iterator
// would panic.
c.Subscribe(prefix+ads.WildcardSubscription, testutils.NewSubscriptionHandler(notify))
c.Subscribe(ads.WildcardSubscription, testutils.NewSubscriptionHandler(notify))

c.SetResource(r1, noTime)

Expand Down