server

package
v0.0.0-...-f1836c7 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package server produces a binary called testserver, which serves HTTP on a specified port with a specified error rate and latency distribution.

Index

Constants

View Source
const (
	// TestServerIDHeader is the name of an HTTP header containing the
	// test server's ID.
	TestServerIDHeader = "TestServer-ID"

	// TestServerForceResponseCode is the name of an HTTP query
	// parameter indicating the HTTP response code that should set for
	// the request.
	TestServerForceResponseCode = "force-response-code"

	// TestServerEchoHeadersWithPrefix is the name of an HTTP query
	// parameter that causes HTTP headers in the request starting with
	// given prefix (the parameter's value) to be echoed in the
	// response. May be repeated to render multiple prefixes.
	TestServerEchoHeadersWithPrefix = "echo-headers-with-prefix"
)
View Source
const (
	DefaultErrorStatus = 503
)

Variables

This section is empty.

Functions

This section is empty.

Types

type TestHandler

type TestHandler struct {
	TestServer *TestServer
	ID         string
}

TestHandler is an http.Handler that implements the TestServer.

func (TestHandler) ServeHTTP

func (th TestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type TestServer

type TestServer struct {
	// contains filtered or unexported fields
}

TestServer represents one or more HTTP listeners.

func NewTestServer

func NewTestServer(
	ports []string,
	errorRate float64,
	latencyMean time.Duration,
	latencyStdDev time.Duration,
	verbose bool,
	override http.HandlerFunc,
) (*TestServer, error)

NewTestServer creates a new TestServer with the given configuration. The error rate is expressed as a percentage and must be between 0 and 100, inclusive. Duplicate ports are ignored.

func NewTestServerWithDynamicPorts

func NewTestServerWithDynamicPorts(
	listenerIDs []string,
	errorRate float64,
	latencyMean time.Duration,
	latencyStdDev time.Duration,
	verbose bool,
	override http.HandlerFunc,
) (*TestServer, error)

NewTestServerWithDynamicPorts creates a new TestServer with the given configuration. The error rate is expressed as a percentage and must be between 0 and 100, inclusive. A port is selected for each listener dynamically. ListenerIDs must be unique. Responses from a given port will contain the TestServerIDHeader with the corresponding value from listenerIDs. A mapping of IDs to their ports can be obtained via the TestServerControl object returned from ServeAsync.

func (*TestServer) ServeAsync

func (ts *TestServer) ServeAsync() *TestServerControl

ServeAsync starts the configured listeners for this TestServer and returns a TestServerControl which may be used to stop the listeners at a later point in time.

func (*TestServer) SetErrorStatus

func (ts *TestServer) SetErrorStatus(code int) error

SetErrorStatus configures the error code returned when the server's error rate is non-zero. It defaults to 503 (service unavailable). The value must be at least 500 and less than 600.

type TestServerControl

type TestServerControl struct {
	// contains filtered or unexported fields
}

TestServerControl provides the ability to control a TestServer. It provides a mechanism for stopping the server and awaiting the termination of all listeners.

func (*TestServerControl) Await

func (tsc *TestServerControl) Await()

Await waits for all listeners to exit.

func (*TestServerControl) IDPortMap

func (tsc *TestServerControl) IDPortMap() map[string]int

IDPortMap returns a map of the ports used by the TestServer to their respective TestServerIDHeader values. For hard-coded ports the ID is always the port prefixed with a colon.

func (*TestServerControl) Stop

func (tsc *TestServerControl) Stop()

Stop halts the listeners and waits for their associated goroutines to exit.

Directories

Path Synopsis
main

Jump to

Keyboard shortcuts

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