commit
d61444948d
|
@ -0,0 +1,8 @@
|
|||
os:
|
||||
- linux
|
||||
- osx
|
||||
language: go
|
||||
go:
|
||||
- "1.11.x"
|
||||
install:
|
||||
- go get "github.com/pkg/errors"
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/tevino/tcp-shaker)](https://goreportcard.com/report/github.com/tevino/tcp-shaker)
|
||||
[![GoDoc](https://godoc.org/github.com/tevino/tcp-shaker?status.svg)](https://godoc.org/github.com/tevino/tcp-shaker)
|
||||
[![Build Status](https://travis-ci.org/tevino/tcp-shaker.svg?branch=master)](https://travis-ci.org/tevino/tcp-shaker)
|
||||
|
||||
This package is used to perform TCP handshake without ACK, which useful for TCP health checking.
|
||||
|
||||
|
|
|
@ -58,11 +58,6 @@ func TestStopNStartChecker(t *testing.T) {
|
|||
_testChecker(t, c)
|
||||
}
|
||||
|
||||
const (
|
||||
AddrDead = "127.0.0.1:1"
|
||||
AddrTimeout = "10.0.0.0:1"
|
||||
)
|
||||
|
||||
func _startTestServer() (string, context.CancelFunc) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||
addr := ts.Listener.Addr().String()
|
||||
|
|
|
@ -11,6 +11,11 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
AddrDead = "127.0.0.1:1"
|
||||
AddrTimeout = "10.255.255.1:80"
|
||||
)
|
||||
|
||||
// assert calls t.Fatal if the result is false
|
||||
func assert(t *testing.T, result bool) {
|
||||
if !result {
|
||||
|
@ -59,7 +64,7 @@ func TestCheckAddr(t *testing.T) {
|
|||
|
||||
timeout := time.Second * 2
|
||||
// Check dead server
|
||||
err = c.CheckAddr("127.0.0.1:1", timeout)
|
||||
err = c.CheckAddr(AddrDead, timeout)
|
||||
if runtime.GOOS == "linux" {
|
||||
_, ok := err.(*ErrConnect)
|
||||
assert(t, ok)
|
||||
|
@ -73,8 +78,11 @@ func TestCheckAddr(t *testing.T) {
|
|||
assert(t, err == nil)
|
||||
ts.Close()
|
||||
// Check non-routable address, thus timeout
|
||||
err = c.CheckAddr("10.0.0.0:1", timeout)
|
||||
assert(t, err == ErrTimeout)
|
||||
err = c.CheckAddr(AddrTimeout, timeout)
|
||||
if err != ErrTimeout {
|
||||
t.Log("expected ErrTimeout, got ", err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckAddrConcurrently(t *testing.T) {
|
||||
|
@ -87,7 +95,7 @@ func TestCheckAddrConcurrently(t *testing.T) {
|
|||
var wg sync.WaitGroup
|
||||
|
||||
check := func() {
|
||||
if err := c.CheckAddr("10.0.0.0:1", time.Millisecond*50); err == nil {
|
||||
if err := c.CheckAddr(AddrTimeout, time.Millisecond*50); err == nil {
|
||||
t.Fatal("Concurrent testing failed")
|
||||
}
|
||||
wg.Done()
|
||||
|
|
Loading…
Reference in New Issue