-
Type:
Spec Change
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Component/s: Unified Test Format
-
None
-
Needed
-
Summary
Add a way for unified spec tests to assert on the messages a driver writes to the server, including the connection handshake, authentication, and server monitoring.
Motivation
The unified test format can observe command, CMAP, SDAM, and log events. None of these show what was actually put on the wire. Command monitoring excludes the handshake and monitoring commands, and the event objects are built by the driver, so they can't show how a message was encoded or compressed. As a result the handshake and monitoring protocol have no spec tests, only a few prose tests that check that a connection succeeds.
This has let drivers diverge from the specs without anyone noticing. Some examples:
NODE-7881: monitoring hello commands were sent OP_COMPRESSED. The compression spec says hello must never be compressed.CDRIVER-6516: container metadata was sent as client.container instead of client.env.container.RUBY-3974: the backpressure field was nested inside the client document instead of being a top-level field of hello.CSHARP-3788: authentication commands (saslStart and saslContinue) were sent as OP_QUERY, instead of OP_MSG as the auth spec requires once the handshake has shown the server supports it.
In each case the existing tests passed, because nothing could assert on the bytes that were sent. Other drivers may have similar divergences that we haven't found, and there is nothing protecting against future regressions.
Description
Extend the unified test format so a test can record the messages a client writes and assert on them. A prototype in the Java driver demonstrates feasibility. Here is what the prototype covered.
What to observe
- Handshake commands: hello or legacy hello, and the authentication exchange (saslStart, saslContinue, authenticate, and speculativeAuthenticate inside hello).
- Messages on server monitor connections, both the monitor itself and the separate RTT connection.
- Ordinary application commands, so that rules such as "hello is never compressed" can be checked after the handshake too.
How to match
- Assert on the decoded contents of the bytes that are written to the socket.
- Match strictly so that an unexpected field fails the test.
- Decode opcode, flags, OP_MSG sections, and OP_COMPRESSED wrapping, and check that every recorded message is well-formed.
Things tests need
- A way to wait for monitor messages, since monitors run on their own threads. Monitor connections never stop sending, so tests should assert on the first N messages and not on a total.
- A way to set environment variables for client creation.
- Client options that fix which connections exist and what they do: directConnection, serverMonitoringMode, and compressors.
Open questions
- How much of the message layout should the test format expose? Each level catches more bugs but requires more parsing code in every driver:
- The command document only. Catches misplaced or extra fields. Can't see the opcode, flags, compression, or extra sections.
- Plus the envelope: opcode, flags, and for OP_COMPRESSED the compressor and the original opcode. Also catches compressed hello and OP_QUERY used where OP_MSG is required.
- Plus the full layout: OP_MSG sections, and the decompressed message inside OP_COMPRESSED. Also catches an unexpected extra section. Each driver needs a decoder, and decoding compressed messages independently of the driver needs a decompressor for each algorithm. The prototype does this, with the command as shorthand for a single section so most tests look like level 1.
- Which tests to write first. The prototype has tests for the hello field set, serverApi, compression, client.env.container, SCRAM, monitor and RTT connections, and hello never being compressed.