Skip to content

Commit

Permalink
wait for port
Browse files Browse the repository at this point in the history
  • Loading branch information
awootton committed Apr 19, 2024
1 parent 1e3d365 commit e4b123f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
40 changes: 29 additions & 11 deletions test/inabox-harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func StartNode(nodeStart int) (*server.Node, error) {
bindAddr := "127.0.0.1"
port := 4010 + index

WaitForPort(port)

consul := bindAddr + ":8500"

memLimit := 0
Expand Down Expand Up @@ -145,6 +147,8 @@ type LocalProxyControl struct {

func StartProxy(count int, testConfigPath string) *LocalProxyControl {

WaitForPort(4000)

localProxy := &LocalProxyControl{}

localProxy.Stop = make(chan bool)
Expand Down Expand Up @@ -446,27 +450,41 @@ func CheckForClosedPort(port string) bool {
return false // it's still in use.
}

func (state *ClusterLocalState) Release() {
if state.weStartedTheCluster {
state.ProxyControl.Stop <- true
time.Sleep(100 * time.Millisecond)
state.StopNodes()
time.Sleep(100 * time.Millisecond)
}
// we need to wait for port 4000 to become available again
func WaitForPort(port int) {
start := time.Now()
for {
if CheckForClosedPort("4000") {
if CheckForClosedPort(strconv.Itoa(port)) {
break
}
if time.Since(start) > time.Minute*2 {
fmt.Println("CheckForClosedPort timed out")
if time.Since(start) > 2*time.Minute {
fmt.Println("ERROR WaitForPort timed out waiting for port to become available.")
break
}
time.Sleep(100 * time.Millisecond)
}
}

func (state *ClusterLocalState) Release() {
if state.weStartedTheCluster {
state.ProxyControl.Stop <- true
time.Sleep(100 * time.Millisecond)
state.StopNodes()
time.Sleep(100 * time.Millisecond)
}
// // we need to wait for port 4000 to become available again
// start := time.Now()
// for {
// if CheckForClosedPort("4000") {
// break
// }
// if time.Since(start) > time.Minute*2 {
// fmt.Println("CheckForClosedPort timed out")
// break
// }
// time.Sleep(100 * time.Millisecond)
// }
}

func WaitForLocalActive(state *ClusterLocalState) {

allActive := true
Expand Down
3 changes: 2 additions & 1 deletion test/local3+1_zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func TestLocalBasic3then4_continuous(t *testing.T) {
time.Sleep(10 * time.Second)

// release as necessary
// or, just abandon it state.Release()
// or, just abandon it
state.Release()
}

func TestLocalBasic3then4Zip(t *testing.T) {
Expand Down

0 comments on commit e4b123f

Please sign in to comment.