Skip to content

Commit

Permalink
Merge pull request #180 from testcontainers/fix/159-wait-port-windows
Browse files Browse the repository at this point in the history
Fix/159 wait port windows
  • Loading branch information
gianarb authored Apr 14, 2020
2 parents 042661a + adb8f34 commit cabddc2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions wait/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build !windows

package wait

import "syscall"

func isConnRefusedErr(err error) bool {
return err == syscall.ECONNREFUSED
}
9 changes: 9 additions & 0 deletions wait/errors_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wait

import (
"golang.org/x/sys/windows"
)

func isConnRefusedErr(err error) bool {
return err == windows.WSAECONNREFUSED
}
6 changes: 4 additions & 2 deletions wait/host_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net"
"os"
"strconv"
"syscall"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -74,7 +73,7 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT
if err != nil {
if v, ok := err.(*net.OpError); ok {
if v2, ok := (v.Err).(*os.SyscallError); ok {
if v2.Err == syscall.ECONNREFUSED && ctx.Err() == nil {
if isConnRefusedErr(v2.Err) {
time.Sleep(100 * time.Millisecond)
continue
}
Expand All @@ -90,6 +89,9 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT
//internal check
command := buildInternalCheckCommand(hp.Port.Int())
for {
if ctx.Err() != nil {
return ctx.Err()
}
exitCode, err := target.Exec(ctx, []string{"/bin/sh", "-c", command})
if err != nil {
return errors.Wrapf(err, "host port waiting failed")
Expand Down

0 comments on commit cabddc2

Please sign in to comment.