MockSocketServer class

A stand-in server: it reads the subscribe frames a hub sends and pushes generated payloads back for whatever is subscribed.

This is mock mode without a parallel code path — the hub, the codec and the app's stream wiring are the real ones, and only the far end is invented. It also makes a good test double for anything that consumes a hub.

final server = MockSocketServer(
  build: (key, tick) => switch (key.channel) {
    'ticker' => {'symbol': key.args['symbol'], 'last': 64000 + tick},
    'candle' => {'close': 64000 + tick, 'interval': key.args['interval']},
    _ => null,
  },
);

final hub = SocketChannelHub<Object?>(
  transport: server.open,
  codec: codec,
);

The frames it emits match JsonSocketCodec's inbound shape, and its field names are configurable for a codec set up differently.

Constructors

MockSocketServer({required MockPayloadBuilder build, Duration tick = const Duration(seconds: 1), bool ackOps = true, String opField = 'op', String channelField = 'channel', String dataField = 'data', String argsField = 'args', String errorField = 'error', String subscribeOp = 'subscribe', String unsubscribeOp = 'unsubscribe'})
Creates a mock server that answers with build every tick.

Properties

ackOps bool
Whether control frames are answered with a success reply.
final
argsField String
The field holding the argument list of an inbound control frame.
final
build MockPayloadBuilder
Builds the payload for one subscription on one tick.
final
channelField String
The field naming a channel on an outbound data frame.
final
dataField String
The field carrying an outbound payload.
final
errorField String
The field an acknowledgement reports its (absent) error in.
final
hashCode int
The hash code for this object.
no setterinherited
opField String
The field naming an operation, on frames in and out.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
subscribeOp String
The inbound op value that subscribes.
final
subscriptions Set<SubscriptionKey>
What the hub has subscribed to, as read off the wire.
no setter
tick Duration
How often a round of payloads goes out.
final
tickCount int
How many rounds have gone out.
no setter
transport FakeTransport?
The transport currently connected, if any. Exposed so a test can drop the socket with transport!.closeByPeer() and watch the hub come back.
no setter
unsubscribeOp String
The inbound op value that unsubscribes.
final

Methods

dispose() Future<void>
Stops the feed and closes the current socket.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open() FakeTransport
Opens a connection. Pass this straight to a hub as its transport factory.
pump() → void
Sends one round of payloads now, without waiting for the timer.
toString() String
A string representation of this object.
inherited

Operators

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