~samwhited/xmpp

8c2fda199527f9a1caee2bbe7532981c5cfafea8 — Sam Whited a month ago 7725b6c
internal/integration: refactor waitSocket

This was written in a weird way originally. A quick refactor makes it
much nicer to read.

Signed-off-by: Sam Whited <sam@samwhited.com>
1 files changed, 3 insertions(+), 6 deletions(-)

M internal/integration/waitdial.go
M internal/integration/waitdial.go => internal/integration/waitdial.go +3 -6
@@ 11,21 11,18 @@ import (
)

func waitSocket(network, socket string) error {
	connAttempts := 10
	timeout := time.Second
	for {
		if connAttempts--; connAttempts == 0 {
			return fmt.Errorf("failed to bind to %s", socket)
		}
	for connAttempts := 10; connAttempts > 0; connAttempts-- {
		time.Sleep(timeout)
		timeout += 500 * time.Millisecond
		conn, err := net.DialTimeout(network, socket, timeout)
		if err != nil {
			continue
		}
		timeout += 500 * time.Millisecond
		if err = conn.Close(); err != nil {
			return fmt.Errorf("failed to close probe connection: %w", err)
		}
		return nil
	}
	return fmt.Errorf("failed to bind to %s", socket)
}