-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2373 from OffchainLabs/fix-challenges
Make the test signer easier to use in parallel tests
- Loading branch information
Showing
6 changed files
with
100 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,17 @@ | ||
package testhelpers | ||
|
||
import ( | ||
"net" | ||
) | ||
|
||
// FreeTCPPortListener returns a listener listening on an unused local port. | ||
// | ||
// This is useful for tests that need to bind to a port without risking a conflict. | ||
func FreeTCPPortListener() (net.Listener, error) { | ||
// This works because the kernel will assign an unused port when ":0" is opened. | ||
l, err := net.Listen("tcp", "127.0.0.1:0") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return l, nil | ||
} |
This file contains 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,23 @@ | ||
package testhelpers | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
) | ||
|
||
func TestFreeTCPPortListener(t *testing.T) { | ||
aListener, err := FreeTCPPortListener() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
bListener, err := FreeTCPPortListener() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if aListener.Addr().(*net.TCPAddr).Port == bListener.Addr().(*net.TCPAddr).Port { | ||
t.Errorf("FreeTCPPortListener() got same port: %v, %v", aListener, bListener) | ||
} | ||
if aListener.Addr().(*net.TCPAddr).Port == 0 || bListener.Addr().(*net.TCPAddr).Port == 0 { | ||
t.Errorf("FreeTCPPortListener() got port 0") | ||
} | ||
} |