internal_test

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAdminBackendListAsMap

func GetAdminBackendListAsMap(t *testing.T, config *TestConfig) map[string]AdminBackend

GetAdminBackendListAsMap fetches and convert backend list as map

func GetAdminRequest

func GetAdminRequest(t *testing.T, ep string, returnData interface{})

GetAdminRequest perform a HTTP Get request and unmarshal response into supplied returnData

Types

type AdminActionResponse

type AdminActionResponse struct {
	Result     string `json:"result"`
	Reason     string `json:"reason"`
	StatusCode int
}

AdminActionResponse action request response from admin APIs

func GetAdminActionRequest

func GetAdminActionRequest(t *testing.T, ep string) *AdminActionResponse

GetAdminActionRequest perform a HTTP Get request on given endpoint

func PostAdminActionRequest

func PostAdminActionRequest(t *testing.T, ep string, postData []byte) *AdminActionResponse

PostAdminActionRequest perform a HTTP Post request on given endpoint

func (*AdminActionResponse) BadRequest

func (aar *AdminActionResponse) BadRequest() bool

BadRequest returns true if the HTTP response code was 400 (Bad Request)

func (*AdminActionResponse) Failed

func (aar *AdminActionResponse) Failed() bool

Failed returns true if this response states failed

func (*AdminActionResponse) NoActionReqd

func (aar *AdminActionResponse) NoActionReqd() bool

NoActionReqd returns true if this response indicate there was no action taken by the server

func (*AdminActionResponse) String

func (aar *AdminActionResponse) String() string

String returns human readable string

func (*AdminActionResponse) Successful

func (aar *AdminActionResponse) Successful() bool

Successful returns true if this response states success

type AdminBackend

type AdminBackend struct {
	URL               string `json:"url"`
	ID                string `json:"id"`
	ActiveConnections int    `json:"activeConnections"`
	Enabled           bool   `json:"enabled"`
	Tripped           bool   `json:"tripped"`
	TotalConnections  int    `json:"totalConnections"`
	TotalFailures     int    `json:"totalFailures"`
}

AdminBackend as returned from admin API

func GetAdminBackendList

func GetAdminBackendList(t *testing.T, config *TestConfig) []AdminBackend

GetAdminBackendList fetches admin listing from admin

func (*AdminBackend) Add

func (ab *AdminBackend) Add(t *testing.T, config *TestConfig, abConfig *NewBackendData) *AdminActionResponse

Add this backend using admin request to server

func (*AdminBackend) Config

func (ab *AdminBackend) Config(t *testing.T, config *TestConfig) *NewBackendData

Config get config of this backend using admin request to server

func (*AdminBackend) Delete

func (ab *AdminBackend) Delete(t *testing.T, config *TestConfig) *AdminActionResponse

Delete this backend using admin request to server

func (*AdminBackend) Disable

func (ab *AdminBackend) Disable(t *testing.T, config *TestConfig) *AdminActionResponse

Disable this backend using admin request to server

func (*AdminBackend) Enable

func (ab *AdminBackend) Enable(t *testing.T, config *TestConfig) *AdminActionResponse

Enable this backend using admin request to server

func (*AdminBackend) Failover

func (ab *AdminBackend) Failover(t *testing.T, config *TestConfig) *AdminActionResponse

Failover this backend using admin request to server

func (*AdminBackend) Reset

func (ab *AdminBackend) Reset(t *testing.T, config *TestConfig) *AdminActionResponse

Reset this backend's trigger status using admin request to server

type AdminFrontend

type AdminFrontend struct {
	ID string `json:"id"`
}

AdminFrontend frontend as returned from admin API

func GetAdminFrontendList

func GetAdminFrontendList(t *testing.T, config *TestConfig) []AdminFrontend

GetAdminFrontendList fetches and return list of session from admin

func (*AdminFrontend) Pause

func (af *AdminFrontend) Pause(t *testing.T, config *TestConfig) *AdminActionResponse

Pause this frontend using admin request to server

func (*AdminFrontend) Resume

func (af *AdminFrontend) Resume(t *testing.T, config *TestConfig) *AdminActionResponse

Resume this frontend using admin request to server

type AdminSession

type AdminSession struct {
	ID           string `json:"id"`
	URI          string `json:"uri"`
	BackendID    string `json:"backendId"`
	Reconnects   int    `json:"reconnects"`
	MsgsReceived int    `json:"msgsReceived"`
	MsgsSent     int    `json:"msgsSent"`
}

AdminSession session as returned from admin API

func GetAdminSessionList

func GetAdminSessionList(t *testing.T, config *TestConfig) []AdminSession

GetAdminSessionList fetches and return list of session from admin

func (*AdminSession) Abort

func (ss *AdminSession) Abort(t *testing.T, config *TestConfig) *AdminActionResponse

Abort this session using admin request to server

func (*AdminSession) Failover

func (ss *AdminSession) Failover(t *testing.T, config *TestConfig) *AdminActionResponse

Failover this session using admin request to server

type NewBackendData

type NewBackendData struct {
	URL                string   `json:"url"`
	ID                 string   `json:"id"`
	PingTime           string   `json:"ping-time"`
	ReadBufferSize     int      `json:"read-buffer-size"`
	WriteBufferSize    int      `json:"write-buffer-size"`
	BreakerThreshold   int      `json:"breaker-threshold"`
	HandshakeTimeout   string   `json:"handshake-timeout"`
	PassHeaders        []string `json:"pass-headers"`
	AbnormalCloseCodes []int    `json:"abnormal-close-codes"`
}

NewBackendData for sending add backend requests to admin interface

type SvrBuilder

type SvrBuilder func(*in.ServerConfig, *in.Manager) *http.Server

SvrBuilder function to have balancer HTTP server instances created. This is needed to avoid circular import dependency which is not allowed in go.

type TestBackend

type TestBackend struct {
	// Underlying HTTP Server
	HTTPServer *http.Server

	// for upgrading to websockets
	Upgrader *websocket.Upgrader

	// headers to include while accepting connection
	ResponseHeader http.Header

	// true if the server is already listening
	Listening bool

	// all active connections from this server
	Connections *TestBackendConnections

	// function used to respond to incoming messages
	Responder func(*common.WsMessage) *common.WsMessage

	// function for accepting incoming requests
	CustomAcceptor func(w http.ResponseWriter, r *http.Request)

	// If false, all lastXXXX variables are NOT updated
	IgnoreLastTrackers bool
	// contains filtered or unexported fields
}

TestBackend a Websocket server for unit/integration testing

func (*TestBackend) CloseAllConnections

func (ts *TestBackend) CloseAllConnections()

CloseAllConnections closes all open connections after sending NormalClose close message

func (*TestBackend) CloseAllConnectionsWithCode

func (ts *TestBackend) CloseAllConnectionsWithCode(closeCode int)

CloseAllConnectionsWithCode closes all open connections after sending close message with given closeCode

func (*TestBackend) ConnectionCount

func (ts *TestBackend) ConnectionCount() int

ConnectionCount returns connection count estbalished with this server right now

func (*TestBackend) EchoResponder

func (ts *TestBackend) EchoResponder(msg *common.WsMessage) *common.WsMessage

EchoResponder Responds with same message as being received

func (*TestBackend) LastConnectedAt

func (ts *TestBackend) LastConnectedAt() time.Time

LastConnectedAt returns the time at which latest client connection was accepted by this server

func (*TestBackend) LastConnection

func (ts *TestBackend) LastConnection() *websocket.Conn

LastConnection returns the latest client connection accepted by this server

func (*TestBackend) LastHeader

func (ts *TestBackend) LastHeader() http.Header

LastHeader returns the incoming headers of the latest accepted client connection by this server

func (*TestBackend) LastPingAt

func (ts *TestBackend) LastPingAt() time.Time

LastPingAt returns the time at which latest ping was received by this server across any of it's connection

func (*TestBackend) LastReceived

func (ts *TestBackend) LastReceived() *common.WsMessage

LastReceived returns the last message received by this server on any of it's connection

func (*TestBackend) LastSent

func (ts *TestBackend) LastSent() *common.WsMessage

LastSent returns the last message sent by this server across any of it's connection

func (*TestBackend) NilResponder

func (ts *TestBackend) NilResponder(msg *common.WsMessage) *common.WsMessage

NilResponder returns nil, essentially resulting in no response

func (*TestBackend) ResetStats

func (ts *TestBackend) ResetStats()

ResetStats Reset all internal stat counters to zero or nil values

func (*TestBackend) ServeWS

func (ts *TestBackend) ServeWS(w http.ResponseWriter, r *http.Request)

ServeWS acts as a HTTP handler for incoming requests

func (*TestBackend) Start

func (ts *TestBackend) Start()

Start - starts listening for connections

func (*TestBackend) TerminateAllConnections

func (ts *TestBackend) TerminateAllConnections()

TerminateAllConnections closes all open connections without sending any close message

type TestBackendConfig

type TestBackendConfig struct {
	Addr               string   `yaml:"addr"`
	Subprotocol        []string `yaml:"subprotocol"`
	BufferSize         int      `yaml:"buffer-size"`
	IgnoreLastTrackers bool     `yaml:"ignore-last-trackers"`
	Server             *TestBackend
}

TestBackendConfig for integration tests

func (*TestBackendConfig) GetServer

func (cfg *TestBackendConfig) GetServer() *TestBackend

GetServer returns properly initialized backend server. the backend server instance is cached thus repetitive calls to this API will return the same server

type TestBackendConnections

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

TestBackendConnections A lock protected map for safer concurrent access

func (*TestBackendConnections) Add

func (tbc *TestBackendConnections) Add(con *websocket.Conn)

Add an item to map

func (*TestBackendConnections) Contains

func (tbc *TestBackendConnections) Contains(con *websocket.Conn) bool

Contains determines if map contains given item

func (*TestBackendConnections) Delete

func (tbc *TestBackendConnections) Delete(con *websocket.Conn)

Delete an item from map

func (*TestBackendConnections) Len

func (tbc *TestBackendConnections) Len() int

Len size of the map

func (*TestBackendConnections) List

func (tbc *TestBackendConnections) List() []*websocket.Conn

List determines if map contains given item

type TestClient

type TestClient struct {
	Endpoint     string
	Dialer       *websocket.Dialer
	Sent         int
	Received     int
	LastPongAt   time.Time
	WsConnection *websocket.Conn
}

TestClient for unit/integration tests

func (*TestClient) Connect

func (tc *TestClient) Connect() (*http.Response, error)

Connect - connects to endpoint

func (*TestClient) ConnectWithHeaders

func (tc *TestClient) ConnectWithHeaders(reqHeaders http.Header) (*http.Response, error)

ConnectWithHeaders connects to endpoint with provided headers

func (*TestClient) Ping

func (tc *TestClient) Ping(data string) error

Ping send a ping message to server

func (*TestClient) ReadMessage

func (tc *TestClient) ReadMessage() (*common.WsMessage, error)

ReadMessage reads one message from connection

func (*TestClient) ResetStats

func (tc *TestClient) ResetStats()

ResetStats reset all internal stats

func (*TestClient) Send

func (tc *TestClient) Send(msg *common.WsMessage) error

Send sends given message

func (*TestClient) SendBinary

func (tc *TestClient) SendBinary(data string) error

SendBinary sends a binary message

func (*TestClient) SendRecvTestMessage

func (tc *TestClient) SendRecvTestMessage(t *testing.T,
	inMsg interface{},
	expectFailure bool,
	expectDiffResponse bool) []byte

SendRecvTestMessage sends a text message to client and reads response expecting same response form server in return. Returns the received message data slice. You can pass a message yourself, if not passed (nil) then a new text message is created and sent to server.

func (*TestClient) SendText

func (tc *TestClient) SendText(data string) error

SendText sends a text message

func (*TestClient) Subprotocol

func (tc *TestClient) Subprotocol() string

Subprotocol returns the negotiated protocol for the connection.

type TestClientConfig

type TestClientConfig struct {
	Endpoint         string        `yaml:"endpoint"`
	Subprotocol      []string      `yaml:"subprotocol"`
	BufferSize       int           `yaml:"buffer-size"`
	HandshakeTimeout time.Duration `yaml:"handshake-timeout"`
	Connections      *TestClientConnections
}

TestClientConfig for integration tests

func (*TestClientConfig) Close

func (cfg *TestClientConfig) Close(client *TestClient) error

Close closes given client

func (*TestClientConfig) CloseAll

func (cfg *TestClientConfig) CloseAll()

CloseAll closes all client with normal closure code

func (*TestClientConfig) CloseAllWithCode

func (cfg *TestClientConfig) CloseAllWithCode(closeCode int)

CloseAllWithCode closes all clients with given code

func (*TestClientConfig) CloseWithCode

func (cfg *TestClientConfig) CloseWithCode(client *TestClient, closeCode int) error

CloseWithCode closes given client with given code

func (*TestClientConfig) GetClient

func (cfg *TestClientConfig) GetClient() *TestClient

GetClient returns a new client for this config

func (*TestClientConfig) GetConnected

func (cfg *TestClientConfig) GetConnected(t *testing.T,
	headers http.Header,
	expectFailure bool,
	expectedStatusCode int) *TestClient

GetConnected creates a new connection with balancer and returns the connected client. Reports Fatal or Error if connection state is NOT as per expectations.

type TestClientConnections

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

TestClientConnections A lock protected map for safer concurrent access

func (*TestClientConnections) Add

func (tcc *TestClientConnections) Add(con *TestClient)

Add an item to map

func (*TestClientConnections) Contains

func (tcc *TestClientConnections) Contains(con *TestClient) bool

Contains determines if map contains given item

func (*TestClientConnections) Delete

func (tcc *TestClientConnections) Delete(con *TestClient)

Delete an item from map

func (*TestClientConnections) Len

func (tcc *TestClientConnections) Len() int

Len size of the map

func (*TestClientConnections) List

func (tcc *TestClientConnections) List() []*TestClient

List determines if map contains given item

type TestConfig

type TestConfig struct {
	Server            in.ServerConfig      `yaml:"server"`
	Upstream          out.UpstreamConfig   `yaml:"upstream"`
	Clients           []*TestClientConfig  `yaml:"test-clients"`
	Backends          []*TestBackendConfig `yaml:"test-backends"`
	ValidateTestLeaks bool                 `yaml:"validate-test-leaks"`
	InManager         *in.Manager
	OutManager        *out.Manager
	FeServer          *http.Server
	AdmSerer          *http.Server

	RunParallel     bool
	InitialRoutines int // # of goroutines running before *ANY* test case execution is started
	// contains filtered or unexported fields
}

TestConfig configuration for test clients and server for integration tests

func GetFourBkConfig

func GetFourBkConfig() *TestConfig

GetFourBkConfig returns test configuration with four backends

func GetOneBkConfig

func GetOneBkConfig() *TestConfig

GetOneBkConfig returns test configuration with one backend

func GetTwoBkConfig

func GetTwoBkConfig() *TestConfig

GetTwoBkConfig returns test configuration with two backends

func LoadConfig

func LoadConfig(config string) *TestConfig

LoadConfig Loads given configuration from testdata folder

func (*TestConfig) ForParallelTest

func (tc *TestConfig) ForParallelTest() *TestConfig

ForParallelTest creates a new test configuration and configure it to run in parallel.

func (*TestConfig) ForTest

func (tc *TestConfig) ForTest() *TestConfig

ForTest creates a new test configuration IF the tests are configured to run in parallel. If parallel execution is NOT required than current configuration is returned AS-IS.

func (*TestConfig) GetLatestBackend

func (tc *TestConfig) GetLatestBackend() *TestBackend

GetLatestBackend returns the backend test server which accepted the latest connection successfully from balancer. In case none of the backend server have accepted any connection yet than this method will return first backend server

func (*TestConfig) ResetStats

func (tc *TestConfig) ResetStats()

ResetStats reset all stats from all test clients and all backend test servers

func (*TestConfig) StartAll

func (tc *TestConfig) StartAll()

StartAll starts balancer followed by all backends

func (*TestConfig) StartBalancer

func (tc *TestConfig) StartBalancer()

StartBalancer starts the balancer, build frontend and admin http server using provided functions. These functions decouples cyclic import dependencies

func (*TestConfig) StopAll

func (tc *TestConfig) StopAll()

StopAll terminate all connections and stop all running server

func (*TestConfig) StopBalancer

func (tc *TestConfig) StopBalancer()

StopBalancer closes frontend and admin http servers

func (*TestConfig) StopForTest

func (tc *TestConfig) StopForTest()

StopForTest stops the backend and balancer IF the tests are configured to run in parallel. If parallel execution is NOT required than this function doesn't do anything

Jump to

Keyboard shortcuts

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