FakeTransport class

A SocketTransport with no socket behind it, for tests and mock modes.

Everything the far end would do is a method call: emit delivers a frame, emitError reports a socket error, closeByPeer hangs up. Everything the hub sends is recorded in sent.

final transport = FakeTransport();
final hub = SocketChannelHub<Object?>(
  transport: () => transport,
  codec: codec,
);

hub.stream(SubscriptionKey('ticker', {'symbol': 'BTC'})).listen(events.add);
await hub.whenReady();
expect(transport.sent.single, contains('"channel":"ticker"'));

transport.emit('{"channel":"ticker","symbol":"BTC","data":{"last":1}}');

A hub that reconnects calls its transport factory again, so return a new FakeTransport per call — or the same one, to assert it is not reused.

Implemented types

Constructors

FakeTransport({bool autoReady = true, void onSend(Object frame)?})
Creates a fake transport.

Properties

hashCode int
The hash code for this object.
no setterinherited
incoming Stream
Frames arriving from the far end, exactly as the socket delivers them — usually String, sometimes List<int>.
no setteroverride
isClosed bool
Whether close has been called, or the peer hung up.
no setter
onSend → void Function(Object frame)?
Called with each frame the hub sends, before it is added to sent.
final
ready Future<void>
Completes when the socket is open, or with an error if it never opens.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sent List<Object>
Every frame the hub has sent, oldest first.
final

Methods

close() Future<void>
Closes the socket. Must complete even if it was never open.
override
closeByPeer() Future<void>
Closes the socket from the far end, without an error.
completeReady() → void
Lets a pending ready succeed. Only for autoReady: false.
emit(Object? frame) → void
Delivers frame to the hub, as the far end would.
emitError(Object error, [StackTrace? stackTrace]) → void
Reports error on the socket, as a transport-level failure would.
failReady(Object error) → void
Fails a pending ready with error, as a refused connection would.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
send(Object data) → void
Sends one frame. Called only after ready completes.
override
takeSent() List<Object>
The frames sent since the last call to this getter.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited