-
Notifications
You must be signed in to change notification settings - Fork 5
fix: replace deprecated tailscale n.NetMap usage #1144
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
Open
skevetter
wants to merge
5
commits into
main
Choose a base branch
from
devsy/auto/7361f8a2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+202
−20
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ec1742
fix: replace deprecated tailscale n.NetMap usage
skevetter 5955c29
style: update comment
skevetter a4c19ce
fix: subscribe to NotifyPeerChanges in WatchNetmap
skevetter b892b10
fix: decouple netmap status fetch from IPN bus drain
skevetter 3969f4d
fix: eliminate test race in burst-drain regression test
skevetter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| package ts | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "tailscale.com/ipn" | ||
| "tailscale.com/ipn/ipnstate" | ||
| "tailscale.com/tailcfg" | ||
| ) | ||
|
|
||
| // waitUntil polls cond until it reports true, failing the test if it does | ||
| // not become true within timeout. | ||
| func waitUntil(t *testing.T, timeout time.Duration, msg string, cond func() bool) { | ||
| t.Helper() | ||
| deadline := time.Now().Add(timeout) | ||
| for !cond() { | ||
| if time.Now().After(deadline) { | ||
| t.Fatal(msg) | ||
| } | ||
| time.Sleep(time.Millisecond) | ||
| } | ||
| } | ||
|
|
||
| func waitFor(t *testing.T, timeout time.Duration, msg string, ch <-chan struct{}) { | ||
| t.Helper() | ||
| select { | ||
| case <-ch: | ||
| case <-time.After(timeout): | ||
| t.Fatal(msg) | ||
| } | ||
| } | ||
|
|
||
| func selfChangeNotifs(n int) []ipn.Notify { | ||
| notifs := make([]ipn.Notify, n) | ||
| for i := range notifs { | ||
| notifs[i] = ipn.Notify{SelfChange: &tailcfg.Node{}} | ||
| } | ||
| return notifs | ||
| } | ||
|
|
||
| // fakeIPNWatcher replays a fixed sequence of notifications, then blocks until | ||
| // the test signals it to report the watch as closed. | ||
| type fakeIPNWatcher struct { | ||
| notifs []ipn.Notify | ||
| idx atomic.Int32 | ||
| afterFirst chan struct{} | ||
| closed chan struct{} | ||
| } | ||
|
|
||
| func (w *fakeIPNWatcher) Next() (ipn.Notify, error) { | ||
| i := w.idx.Load() | ||
| if i == 1 { | ||
| <-w.afterFirst | ||
| } | ||
| if int(i) < len(w.notifs) { | ||
| w.idx.Add(1) | ||
| return w.notifs[i], nil | ||
| } | ||
| <-w.closed | ||
| return ipn.Notify{}, errors.New("watcher closed") | ||
| } | ||
|
|
||
| // TestWatchNetmapDrainsBurstWhileStatusFetchBlocked verifies that a burst of | ||
| // notifications arriving while fetchStatus is in flight does not stall | ||
| // notification draining: watchNetmap must keep calling watcher.Next() so a | ||
| // burst larger than the IPN bus's 128-entry queue never causes tailscaled to | ||
| // close the watch, and must coalesce the burst into a single follow-up fetch. | ||
| func TestWatchNetmapDrainsBurstWhileStatusFetchBlocked(t *testing.T) { | ||
| const burst = 129 | ||
|
|
||
| watcher := &fakeIPNWatcher{ | ||
| notifs: selfChangeNotifs(burst), | ||
| afterFirst: make(chan struct{}), | ||
| closed: make(chan struct{}), | ||
| } | ||
|
|
||
| firstFetchStarted := make(chan struct{}) | ||
| unblockFirstFetch := make(chan struct{}) | ||
| var fetchCount atomic.Int32 | ||
|
|
||
| fetchStatus := func(context.Context) (*ipnstate.Status, error) { //nolint:unparam // exercises the success path only | ||
| if fetchCount.Add(1) == 1 { | ||
| close(firstFetchStarted) | ||
| <-unblockFirstFetch | ||
| } | ||
| return &ipnstate.Status{}, nil | ||
| } | ||
|
|
||
| var callbackCount atomic.Int32 | ||
| callback := func(*ipnstate.Status) { callbackCount.Add(1) } | ||
|
|
||
| errc := make(chan error, 1) | ||
| go func() { | ||
| errc <- watchNetmap(context.Background(), watcher, fetchStatus, callback) | ||
| }() | ||
|
|
||
| waitFor(t, 5*time.Second, "first status fetch never started", firstFetchStarted) | ||
| close(watcher.afterFirst) | ||
|
|
||
| waitUntil(t, 5*time.Second, "watcher stalled while status fetch was blocked", func() bool { | ||
| return watcher.idx.Load() == burst | ||
| }) | ||
|
|
||
| close(unblockFirstFetch) | ||
|
|
||
| waitUntil(t, 5*time.Second, "expected a coalesced follow-up fetch", func() bool { | ||
| return fetchCount.Load() >= 2 | ||
| }) | ||
|
|
||
| if got := fetchCount.Load(); got != 2 { | ||
| t.Errorf( | ||
| "fetchStatus called %d times, want exactly 2 (initial + one coalesced follow-up)", | ||
| got, | ||
| ) | ||
| } | ||
| if got := callbackCount.Load(); got != 2 { | ||
| t.Errorf("callback invoked %d times, want 2", got) | ||
| } | ||
|
|
||
| close(watcher.closed) | ||
| if err := <-errc; err == nil { | ||
| t.Fatal("watchNetmap returned nil error after watcher closed, want an error") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.