tcputil

package module
v0.0.0-...-d3c7f98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2018 License: MIT Imports: 5 Imported by: 7

README

tcputil

Some Utilities To Help Your TCP-Related testing

Build Status GoDoc

SYNOPSIS

  p, err := EmptyPort()
  if err != nil {
    log.Fatal(err)
  }

  cmd := exec.Command("memcached", "-p", fmt.Sprintf("%d", p))
  go cmd.Run()

  err = WaitLocalPort(p, 30 * time.Second)
  if err != nil {
    log.Fatal(err)
  }

  // Now do whatever with memcached!

  cmd.Process.Kill()

For a higher level wrapper for testing network servers on random local ports, see go-tcptest

API docs: http://godoc.org/github.com/lestrrat-go/tcputil

Documentation

Overview

Example
p, err := EmptyPort()
if err != nil {
	log.Fatal(err)
}

cmd := exec.Command("memcached", "-p", fmt.Sprintf("%d", p))
cmd.SysProcAttr = &syscall.SysProcAttr{
	Setpgid: true,
}
go cmd.Run()

err = WaitLocalPort(p, 30*time.Second)
if err != nil {
	log.Fatal(err)
}

// Now do whatever with memcached!

cmd.Process.Kill()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyPort

func EmptyPort() (int, error)

EmptyPort looks for an empty port to listen on local interface.

func WaitLocalPort

func WaitLocalPort(port int, dur time.Duration) error

WaitLocalPort until you can connect to `port` on localhost, up to `dur` amount of time

func WaitPort

func WaitPort(addr string, dur time.Duration) error

WaitPort waits until you can connect to `addr`, up to `dur` amount of time

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL