test

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package test contains the testing types for wire/net.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestConnPair

func NewTestConnPair() (a wirenet.Conn, b wirenet.Conn)

NewTestConnPair creates endpoints that are connected via pipes.

Types

type Conn added in v0.4.1

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

Conn is a testing connection.

func (*Conn) Close added in v0.4.1

func (c *Conn) Close() error

Close closes the Conn.

func (*Conn) IsClosed added in v0.4.1

func (c *Conn) IsClosed() bool

IsClosed returns whether the Conn is already closed.

func (*Conn) Recv added in v0.4.1

func (c *Conn) Recv() (e *wire.Envelope, err error)

Recv receives an envelope.

func (*Conn) Send added in v0.4.1

func (c *Conn) Send(e *wire.Envelope) (err error)

Send sends an envelope.

type ConnHub

type ConnHub struct {
	sync.Closer
	// contains filtered or unexported fields
}

ConnHub is a factory for creating and connecting test dialers and listeners.

func (*ConnHub) Close

func (h *ConnHub) Close() (err error)

Close closes the ConnHub and all its listeners.

func (*ConnHub) NewNetDialer

func (h *ConnHub) NewNetDialer() *Dialer

NewNetDialer creates a new test dialer. Registers the new dialer in the hub. Panics if the hub is closed.

func (*ConnHub) NewNetListener

func (h *ConnHub) NewNetListener(addr wire.Address) *Listener

NewNetListener creates a new test listener for the given address. Registers the new listener in the hub. Panics if the address was already entered or the hub is closed.

type Dialer

type Dialer struct {
	sync.Closer
	// contains filtered or unexported fields
}

Dialer is a test dialer that can dial connections to Listeners via a ConnHub.

func NewDialer added in v0.9.0

func NewDialer(hub *ConnHub) *Dialer

NewDialer creates a new test dialer.

func (*Dialer) Close

func (d *Dialer) Close() error

Close closes a connection.

func (*Dialer) Dial

func (d *Dialer) Dial(ctx context.Context, address wire.Address, ser wire.EnvelopeSerializer) (wirenet.Conn, error)

Dial tries to connect to a wire.

func (*Dialer) NumDialed

func (d *Dialer) NumDialed() int

NumDialed returns how many peers have been dialed.

type Listener

type Listener struct {
	sync.Closer
	// contains filtered or unexported fields
}

Listener is a mocked listener that can be used to control and examine a listener. Accept() calls can be manually controlled via Put(). Accepted() tracks the number of accepted connections. IsClosed() can be used to detect whether a Listener is still open.

func NewNetListener

func NewNetListener() *Listener

NewNetListener creates a new test listener.

func (*Listener) Accept

Accept returns the next connection that is enqueued via Put(). This function blocks until either Put() is called or until the listener is closed.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the test listener. This aborts any ongoing Accept() call and all future Accept() calls will fail. If the listener is already closed, returns an error.

func (*Listener) NumAccepted

func (l *Listener) NumAccepted() int

NumAccepted returns the number of connections that have been accepted by the listener. Note that this number is updated before Accept() returns, but not necessarily before Put() returns.

func (*Listener) Put

func (l *Listener) Put(ctx context.Context, conn wirenet.Conn) bool

Put enqueues one connection to be returned by Accept(). If the listener is already closed, does nothing. This function blocks until either Accept() is called or until the listener is closed. Returns whether the connection has been retrieved by Accept().

Note that if Put() is called in parallel, there is no ordering guarantee for the accepted connections.

Jump to

Keyboard shortcuts

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