mirror of
https://github.com/StockSharp/StockSharp.git
synced 2026-12-04 00:21:31 +00:00
Every test written during the coverage review, in one commit: 105 files, about 32,000 lines added. No product code is touched here - what the tests found is repaired in the commit that follows. WHERE THEY CAME FROM. Three audits read the core and its suite side by side and filed 295 findings. Each was taken as a claim to be disproved rather than believed: of the defects claimed, most did not survive a second reading - an unreachable trigger, a promise nobody ever made, behaviour already covered, and in one case a property the model no longer has, so the test could not be written at all. What survived is here. WHAT THE TESTS ARE. Three kinds, and the difference matters. A hole: behaviour the core has and nothing checked. Most of the new files are this - the adapters that filter a depth, hold a candle, track a lookup, associate a security or loop a message back; the message clone that must not share state with its original; the generators behind localized strings and media names; the round trip of a diagram strategy and of a FIX data type. A test that proved nothing: a name that promised one thing while the assertion checked another, an assertion that could not fail, an expected value copied from whatever the code returned that day. Those were rewritten in place to say what they were named for, and several of them go red doing it. A defect: a promise the core makes and does not keep. Those tests are red, and they stay red until the next commit repairs them - a red test is the record of the defect, and there is nowhere else the record would be read. HOW THEY ARE WRITTEN. From the promise, not from the implementation: the expected value is what the caller is owed, never what the method happens to return. Every assertion carries a message saying what was owed to whom, so a failure reads as a sentence rather than as two numbers that differ. Claude-Session: https://claude.ai/code/session_01LjT4RKLsz3vBd8eSERZTde
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
namespace StockSharp.Tests;
|
|
|
|
using System.Text;
|
|
|
|
using StockSharp.Fix.Native;
|
|
|
|
/// <summary>
|
|
/// The incoming FIX read is bounded. The reader accumulates a field's bytes until the SOH
|
|
/// terminator, so with MaxBytes at int.MaxValue an unauthenticated connection could stream an
|
|
/// unterminated field and grow the buffer to ~2 GB. The byte counter has to run even when the
|
|
/// checksum is disabled, or the cap never fires on a checksum-off session.
|
|
/// </summary>
|
|
[TestClass]
|
|
public class FixReadMaxBytesTests : BaseTestClass
|
|
{
|
|
[TestMethod]
|
|
public async Task ReadStringAsync_UnterminatedFieldBeyondMaxBytes_Throws_EvenWithChecksumDisabled()
|
|
{
|
|
// 100 bytes, none of them SOH (0x01) — an unterminated field.
|
|
var data = new byte[100];
|
|
for (var i = 0; i < data.Length; i++)
|
|
data[i] = (byte)'A';
|
|
|
|
var reader = new TextFixReader(new MemoryStream(data), Encoding.UTF8)
|
|
{
|
|
MaxBytes = 10,
|
|
CheckSumDisabled = true,
|
|
};
|
|
|
|
var threw = false;
|
|
try
|
|
{
|
|
await ((IFixReader)reader).ReadStringAsync(CancellationToken);
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
threw = true;
|
|
}
|
|
|
|
threw.AssertTrue("an unterminated field beyond MaxBytes must throw (the cap), not grow unbounded — the counter must run with the checksum off too");
|
|
}
|
|
}
|