-
Notifications
You must be signed in to change notification settings - Fork 887
chore: Update pion/udp and improve parallel/non-parallel tests #7164
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,8 @@ import ( | |
"github.com/coder/coder/testutil" | ||
) | ||
|
||
//nolint:tparallel,paralleltest // Subtests require setup that must not be done in parallel. | ||
func TestPortForward(t *testing.T) { | ||
t.Parallel() | ||
t.Skip("These tests flake... a lot. It seems related to the Tailscale change, but all other tests pass...") | ||
|
||
t.Run("None", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
@@ -116,106 +114,102 @@ func TestPortForward(t *testing.T) { | |
workspace = runAgent(t, client, user.UserID) | ||
) | ||
|
||
for _, c := range cases { //nolint:paralleltest // the `c := c` confuses the linter | ||
for _, c := range cases { | ||
c := c | ||
// Delay parallel tests here because setupLocal reserves | ||
// a free open port which is not guaranteed to be free | ||
// between the listener closing and port-forward ready. | ||
t.Run(c.name, func(t *testing.T) { | ||
t.Run("OnePort", func(t *testing.T) { | ||
p1 := setupTestListener(t, c.setupRemote(t)) | ||
|
||
// Create a flag that forwards from local to listener 1. | ||
localAddress, localFlag := c.setupLocal(t) | ||
flag := fmt.Sprintf(c.flag, localFlag, p1) | ||
|
||
// Launch port-forward in a goroutine so we can start dialing | ||
// the "local" listener. | ||
inv, root := clitest.New(t, "-v", "port-forward", workspace.Name, flag) | ||
clitest.SetupConfig(t, client, root) | ||
pty := ptytest.New(t) | ||
inv.Stdin = pty.Input() | ||
inv.Stdout = pty.Output() | ||
inv.Stderr = pty.Output() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
errC := make(chan error) | ||
go func() { | ||
errC <- inv.WithContext(ctx).Run() | ||
}() | ||
pty.ExpectMatch("Ready!") | ||
|
||
t.Parallel() // Port is reserved, enable parallel execution. | ||
|
||
// Open two connections simultaneously and test them out of | ||
// sync. | ||
d := net.Dialer{Timeout: testutil.WaitShort} | ||
c1, err := d.DialContext(ctx, c.network, localAddress) | ||
require.NoError(t, err, "open connection 1 to 'local' listener") | ||
defer c1.Close() | ||
c2, err := d.DialContext(ctx, c.network, localAddress) | ||
require.NoError(t, err, "open connection 2 to 'local' listener") | ||
defer c2.Close() | ||
testDial(t, c2) | ||
testDial(t, c1) | ||
|
||
cancel() | ||
err = <-errC | ||
require.ErrorIs(t, err, context.Canceled) | ||
}) | ||
t.Run(c.name+"_OnePort", func(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may also contribute to stability, one less test indentation. We probably need to start considering depth of tests and their interactions with each other or limiting depth to parent + subtest, not subsubtest. |
||
p1 := setupTestListener(t, c.setupRemote(t)) | ||
|
||
//nolint:paralleltest | ||
t.Run("TwoPorts", func(t *testing.T) { | ||
var ( | ||
p1 = setupTestListener(t, c.setupRemote(t)) | ||
p2 = setupTestListener(t, c.setupRemote(t)) | ||
) | ||
|
||
// Create a flags for listener 1 and listener 2. | ||
localAddress1, localFlag1 := c.setupLocal(t) | ||
localAddress2, localFlag2 := c.setupLocal(t) | ||
flag1 := fmt.Sprintf(c.flag, localFlag1, p1) | ||
flag2 := fmt.Sprintf(c.flag, localFlag2, p2) | ||
|
||
// Launch port-forward in a goroutine so we can start dialing | ||
// the "local" listeners. | ||
inv, root := clitest.New(t, "-v", "port-forward", workspace.Name, flag1, flag2) | ||
clitest.SetupConfig(t, client, root) | ||
pty := ptytest.New(t) | ||
inv.Stdin = pty.Input() | ||
inv.Stdout = pty.Output() | ||
inv.Stderr = pty.Output() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
errC := make(chan error) | ||
go func() { | ||
errC <- inv.WithContext(ctx).Run() | ||
}() | ||
pty.ExpectMatch("Ready!") | ||
|
||
t.Parallel() // Port is reserved, enable parallel execution. | ||
|
||
// Open a connection to both listener 1 and 2 simultaneously and | ||
// then test them out of order. | ||
d := net.Dialer{Timeout: testutil.WaitShort} | ||
c1, err := d.DialContext(ctx, c.network, localAddress1) | ||
require.NoError(t, err, "open connection 1 to 'local' listener 1") | ||
defer c1.Close() | ||
c2, err := d.DialContext(ctx, c.network, localAddress2) | ||
require.NoError(t, err, "open connection 2 to 'local' listener 2") | ||
defer c2.Close() | ||
testDial(t, c2) | ||
testDial(t, c1) | ||
|
||
cancel() | ||
err = <-errC | ||
require.ErrorIs(t, err, context.Canceled) | ||
}) | ||
// Create a flag that forwards from local to listener 1. | ||
localAddress, localFlag := c.setupLocal(t) | ||
flag := fmt.Sprintf(c.flag, localFlag, p1) | ||
|
||
// Launch port-forward in a goroutine so we can start dialing | ||
// the "local" listener. | ||
inv, root := clitest.New(t, "-v", "port-forward", workspace.Name, flag) | ||
clitest.SetupConfig(t, client, root) | ||
pty := ptytest.New(t) | ||
inv.Stdin = pty.Input() | ||
inv.Stdout = pty.Output() | ||
inv.Stderr = pty.Output() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
errC := make(chan error) | ||
go func() { | ||
errC <- inv.WithContext(ctx).Run() | ||
}() | ||
pty.ExpectMatch("Ready!") | ||
|
||
t.Parallel() // Port is reserved, enable parallel execution. | ||
|
||
// Open two connections simultaneously and test them out of | ||
// sync. | ||
d := net.Dialer{Timeout: testutil.WaitShort} | ||
c1, err := d.DialContext(ctx, c.network, localAddress) | ||
require.NoError(t, err, "open connection 1 to 'local' listener") | ||
defer c1.Close() | ||
c2, err := d.DialContext(ctx, c.network, localAddress) | ||
require.NoError(t, err, "open connection 2 to 'local' listener") | ||
defer c2.Close() | ||
testDial(t, c2) | ||
testDial(t, c1) | ||
|
||
cancel() | ||
err = <-errC | ||
require.ErrorIs(t, err, context.Canceled) | ||
}) | ||
|
||
t.Run(c.name+"_TwoPorts", func(t *testing.T) { | ||
var ( | ||
p1 = setupTestListener(t, c.setupRemote(t)) | ||
p2 = setupTestListener(t, c.setupRemote(t)) | ||
) | ||
|
||
// Create a flags for listener 1 and listener 2. | ||
localAddress1, localFlag1 := c.setupLocal(t) | ||
localAddress2, localFlag2 := c.setupLocal(t) | ||
flag1 := fmt.Sprintf(c.flag, localFlag1, p1) | ||
flag2 := fmt.Sprintf(c.flag, localFlag2, p2) | ||
|
||
// Launch port-forward in a goroutine so we can start dialing | ||
// the "local" listeners. | ||
inv, root := clitest.New(t, "-v", "port-forward", workspace.Name, flag1, flag2) | ||
clitest.SetupConfig(t, client, root) | ||
pty := ptytest.New(t) | ||
inv.Stdin = pty.Input() | ||
inv.Stdout = pty.Output() | ||
inv.Stderr = pty.Output() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
errC := make(chan error) | ||
go func() { | ||
errC <- inv.WithContext(ctx).Run() | ||
}() | ||
pty.ExpectMatch("Ready!") | ||
|
||
t.Parallel() // Port is reserved, enable parallel execution. | ||
|
||
// Open a connection to both listener 1 and 2 simultaneously and | ||
// then test them out of order. | ||
d := net.Dialer{Timeout: testutil.WaitShort} | ||
c1, err := d.DialContext(ctx, c.network, localAddress1) | ||
require.NoError(t, err, "open connection 1 to 'local' listener 1") | ||
defer c1.Close() | ||
c2, err := d.DialContext(ctx, c.network, localAddress2) | ||
require.NoError(t, err, "open connection 2 to 'local' listener 2") | ||
defer c2.Close() | ||
testDial(t, c2) | ||
testDial(t, c1) | ||
|
||
cancel() | ||
err = <-errC | ||
require.ErrorIs(t, err, context.Canceled) | ||
}) | ||
} | ||
|
||
// Test doing TCP and UDP at the same time. | ||
//nolint:paralleltest | ||
t.Run("All", func(t *testing.T) { | ||
var ( | ||
dials = []addr{} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping removing parallel from the parent will allow these to run more stable, so for now let's re-enable these tests.