Skip to content

Commit 60b3eca

Browse files
committed
Fix flaky tests: MessageChannel time ordering and emulator comparison
- MessageChannelTests: use seconds instead of milliseconds to avoid race between enqueue and dequeue in sorted queue - MarketEmulatorComparisonTests: use real order book instead of synthetic (V2 intentionally fills at order price for synthetic books)
1 parent c09c757 commit 60b3eca

2 files changed

Lines changed: 7 additions & 18 deletions

File tree

Tests/MarketEmulatorComparisonTests.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,32 +1080,21 @@ public async Task OrderExecution_WithSyntheticBook()
10801080
await InitMoney(emuV1, now);
10811081
await InitMoney(emuV2, now);
10821082

1083-
// Send tick to create synthetic book
1084-
var tick = new ExecutionMessage
1085-
{
1086-
SecurityId = secId,
1087-
LocalTime = now,
1088-
ServerTime = now,
1089-
DataTypeEx = DataType.Ticks,
1090-
TradePrice = 100,
1091-
TradeVolume = 10,
1092-
TradeId = 1,
1093-
};
1094-
1095-
await emuV1.SendInMessageAsync(tick.TypedClone(), CancellationToken);
1096-
await emuV2.SendInMessageAsync(tick.TypedClone(), CancellationToken);
1083+
// Send real order book (not synthetic from tick) so both emulators match identically
1084+
await SendBook(emuV1, secId, now, bid: 99, ask: 100);
1085+
await SendBook(emuV2, secId, now, bid: 99, ask: 100);
10971086

10981087
resV1.Clear();
10991088
resV2.Clear();
11001089

1101-
// Now try to place an order - the synthetic book should allow execution
1090+
// Now try to place an order - should cross the ask at 100
11021091
var order = new OrderRegisterMessage
11031092
{
11041093
SecurityId = secId,
11051094
LocalTime = now.AddMilliseconds(1),
11061095
TransactionId = 1,
11071096
Side = Sides.Buy,
1108-
Price = 101, // Above tick price, should cross spread
1097+
Price = 101, // Above ask price, should cross spread
11091098
Volume = 5,
11101099
OrderType = OrderTypes.Limit,
11111100
TimeInForce = TimeInForce.PutInQueue,

Tests/MessageChannelTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,10 @@ public async Task InMemoryChannel_MessageByLocalTimeQueue_OutOfOrderTimes_SortsC
595595
var baseTime = DateTime.UtcNow;
596596
var messages = new List<TimeMessage>();
597597

598-
// Create messages with shuffled times
598+
// Create messages with shuffled times (use seconds to avoid race between enqueue and dequeue)
599599
for (int i = 0; i < messageCount; i++)
600600
{
601-
messages.Add(CreateTimeMessage(baseTime.AddMilliseconds(i * 100)));
601+
messages.Add(CreateTimeMessage(baseTime.AddSeconds(i)));
602602
}
603603

604604
// Shuffle and send

0 commit comments

Comments
 (0)