Skip to content

Commit

Permalink
Make the InmemTransport.timeout field configurable
Browse files Browse the repository at this point in the history
The NewInmemTransportWithTimeout contructor supports specifying a
custom RPC timeout for an InmemTransport instance.

This timeout appears to be the only non-configurable one when creating
test-oriented Raft instances (i.e. using the in-memory version of the
various dependencies). All other timeouts can be set using Config.

Being able to tweak this timeout is useful when running tests on
machines under relatively high load, where a low timeout might produce
spurious errors.
  • Loading branch information
freeekanayaka committed Mar 3, 2018
1 parent a3fb458 commit cfdcd7e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions inmem_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,29 @@ type InmemTransport struct {
timeout time.Duration
}

// NewInmemTransport is used to initialize a new transport
// and generates a random local address if none is specified
func NewInmemTransport(addr ServerAddress) (ServerAddress, *InmemTransport) {
// NewInmemTransportWithTimeout is used to initialize a new transport and
// generates a random local address if none is specified. The given timeout
// will be used to decide how long to wait for a connected peer to process the
// RPCs that we're sending it. See also Connect() and Consumer().
func NewInmemTransportWithTimeout(addr ServerAddress, timeout time.Duration) (ServerAddress, *InmemTransport) {
if string(addr) == "" {
addr = NewInmemAddr()
}
trans := &InmemTransport{
consumerCh: make(chan RPC, 16),
localAddr: addr,
peers: make(map[ServerAddress]*InmemTransport),
timeout: 50 * time.Millisecond,
timeout: timeout,
}
return addr, trans
}

// NewInmemTransport is used to initialize a new transport
// and generates a random local address if none is specified
func NewInmemTransport(addr ServerAddress) (ServerAddress, *InmemTransport) {
return NewInmemTransportWithTimeout(addr, 50*time.Millisecond)
}

// SetHeartbeatHandler is used to set optional fast-path for
// heartbeats, not supported for this transport.
func (i *InmemTransport) SetHeartbeatHandler(cb func(RPC)) {
Expand Down

0 comments on commit cfdcd7e

Please sign in to comment.