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 RefreshPerNSWorkerManager and RemoveOverride for tests #3837

Merged
merged 1 commit into from
Jan 26, 2023
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
14 changes: 9 additions & 5 deletions service/worker/pernamespaceworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,17 @@ func (wm *perNamespaceWorkerManager) namespaceCallback(ns *namespace.Namespace,
go wm.getWorkerByNamespace(ns).refreshWithNewNamespace(ns, deleted)
}

func (wm *perNamespaceWorkerManager) refreshAll() {
wm.lock.Lock()
defer wm.lock.Unlock()
for _, worker := range wm.workers {
go worker.refreshWithExistingNamespace()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible that refershAll get called multiple times before refreshWithExistingNamespace() finished and end up having multiple goroutines running refreshWithExistingNamespace()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's possible before this change too. The refresh* functions are written so that it's ok, they use a lock and some state to synchronize. The worst that should happen is extra calls to get dynamicconfig values

}
}

func (wm *perNamespaceWorkerManager) membershipChangedListener() {
for range wm.membershipChangedCh {
wm.lock.Lock()
for _, worker := range wm.workers {
go worker.refreshWithExistingNamespace()
}
wm.lock.Unlock()
wm.refreshAll()
}
}

Expand Down
5 changes: 5 additions & 0 deletions service/worker/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,8 @@ func (s *Service) ensureSystemNamespaceExists(
)
}
}

// This is intended for use by integration tests only.
func (s *Service) RefreshPerNSWorkerManager() {
s.perNamespaceWorkerManager.refreshAll()
}
6 changes: 6 additions & 0 deletions tests/dynamicconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func (d *dcClient) OverrideValue(name dynamicconfig.Key, value any) {
d.overrides[name] = value
}

func (d *dcClient) RemoveOverride(name dynamicconfig.Key) {
d.Lock()
defer d.Unlock()
delete(d.overrides, name)
}

// newTestDCClient - returns a dynamic config client for integration testing
func newTestDCClient(fallback dynamicconfig.Client) *dcClient {
return &dcClient{
Expand Down