diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 31c6228..42fd2dd 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -16,7 +16,7 @@ jobs: name: Build and test strategy: matrix: - runs-on: [macos-latest, ubuntu-latest] + runs-on: [macos-latest, ubuntu-latest, windows-latest] runs-on: ${{ matrix.runs-on }} steps: - uses: actions/checkout@v2 diff --git a/internal/network/wait.go b/internal/network/wait.go index d0d2378..a4e2f64 100644 --- a/internal/network/wait.go +++ b/internal/network/wait.go @@ -19,7 +19,7 @@ type connectResult struct { err error } -func waitForAddress(address syntax.Address) <-chan bool { +func waitForAddressForever(address syntax.Address) <-chan bool { available := make(chan bool, 1) go func() { for { @@ -46,7 +46,7 @@ func waitForAddressWithTimeout(address syntax.Address, timeout time.Duration, st err := error(nil) select { - case <-waitForAddress(address): + case <-waitForAddressForever(address): duration = time.Now().Sub(startedAt) case <-deadline: err = fmt.Errorf("Failed to connect to %s for %s.", address, timeout) diff --git a/internal/network/wait_test.go b/internal/network/wait_test.go index d24bfab..9d0b5a5 100644 --- a/internal/network/wait_test.go +++ b/internal/network/wait_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestWaitForAddress(t *testing.T) { +func TestWaitForAddressSuccess(t *testing.T) { testlab.WithListeningPort(t, func(address syntax.Address) { port := address.Port @@ -27,16 +27,27 @@ func TestWaitForAddress(t *testing.T) { deadlineCombined := time.After(2 * time.Second) for _, address := range addresses { - available := waitForAddress(address) + available := waitForAddressForever(address) select { case <-available: case <-deadlineCombined: - t.Errorf("waitForAddress should be long done by now.") + t.Errorf("waitForAddressForever should be long done by now.") } } }) } +func TestWaitForAddressFailure(t *testing.T) { + testlab.WithUnusedPort(t, func(address syntax.Address) { + timeout := 1250 * time.Millisecond // small to not blow up test runtime + select { + case <-waitForAddressForever(address): + t.Errorf("waitForAddressForever was expected to never finish.") + case <-time.After(timeout): + } + }) +} + func TestWaitForAddressWithTimeoutSuccess(t *testing.T) { testlab.WithListeningPort(t, func(address syntax.Address) { timeout := 2 * time.Second