Skip to content

Testing

The tests are one GoogleTest binary, slick-trader-tests, built from tests/ and the test files that brokers contribute. Most files pin down a bug that once shipped, and say so in a header comment.

Build and run

The suite is on by default when slick-trader is the top-level project (SLICK_TRADER_BUILD_TESTS) and needs GTest from vcpkg. See Building.

ctest --test-dir build -C Debug --output-on-failure      # -C is for multi-config generators
build/tests/slick-trader-tests                           # the binary directly (build/tests/<Config>/ on Visual Studio)

gtest_discover_tests lists the tests by running the binary at ctest time (PRE_TEST discovery), so the binary must be runnable. Each test gets a 60 second timeout. Filter either way:

ctest --test-dir build -C Debug -R WebServerHttp --output-on-failure
build/tests/slick-trader-tests --gtest_filter='MdSubscription*:BrokerRegistry*'
build/tests/slick-trader-tests --gtest_list_tests

test_main.cpp starts slick-logger before anything logs. The console shows errors only. The logger level is warn, and warnings reach the LogCount sink (below), so a test can assert that a line was logged. Several tests drive the "foreign order ignored" paths on purpose, which are chatty at debug level.

Layout

Path Role
tests/CMakeLists.txt Lists the test sources, builds the two test plugins, links the brokers and registers tests with CTest
tests/test_*.cpp The suites. One file per area
tests/strategy_manager_fixture.hpp A StrategyManager with everything it needs, driven without its worker thread
tests/fake_sim.hpp A fake slick-sim CLI port
tests/raw_client.hpp A raw-socket HTTP and WebSocket client
tests/log_count.hpp Counts log lines by text
tests/probe_plugin.cpp, tests/stale_plugin.cpp The two test plugins

Fixtures

StrategyManagerFixture holds a PositionTracker, PnLCalculator, RiskManager, a small event multiplexer (mux_), a market data request queue for every broker (md_qs_), an order queue (order_q_) and a StrategyManager (manager_) wired to all of them. Events go in through manager_.process_event(), requests come out of md_qs_ and order_q_, and what the manager publishes itself can be read off mux_. The worker thread is never started, so tests are deterministic. add_strategy(strategy, params) initializes a strategy as the engine would.

FakeSim listens on a loopback port and speaks slick-sim's CLI wire format on a thread of its own. A test sets what it answers (status, list of feeds, version) and reads back how often it was asked and how many starts came. It can also refuse a command, as an older slick-sim does, and drop the connection.

RawClient sends what a browser sends over a plain socket (POSIX or Winsock): GET, POST, PUT and DELETE with JSON bodies, bodies split across two writes, keep-alive requests, the WebSocket handshake and masked frames, close-frame handling, and a small receive buffer to imitate a slow client. free_port() asks the OS for an unused port. Include it after the WebServer headers, since on Windows it pulls in winsock2.h.

LogCount(text) counts WARN-and-above log lines whose format string contains text, from the moment it is made. It flushes the logger when read. It is how a test proves a warning went out once, or not at all.

Test plugins

Both are built like a real strategy: a SHARED library, statically linked to slick-trader-core, so each owns a private copy of every singleton in that library. The paths reach the tests as compile definitions.

Plugin Definition Used to
probe_plugin SLICK_TRADER_TEST_PLUGIN_PATH Report what its own BrokerStatusRegistry says, through probe_is_order_enabled, probe_is_order_connected and probe_initialized. That makes the cross-module registry bug observable
stale_plugin SLICK_TRADER_TEST_STALE_PLUGIN_PATH Export only create_strategy and destroy_strategy, as plugins did before they named the API they were built against. StrategyLoader has to refuse it

SLICK_TRADER_WEB_SETUP_SCRIPT carries the path to scripts/slick-trader-web.bat for the Windows setup script test.

Coverage map

File What it pins down
test_broker_status_injection.cpp A loaded plugin sees the host's BrokerStatusRegistry, not its private copy. Plugin extension per platform. A plugin of another API version is refused. A config with no parameters still initializes the strategy
test_strategy_ownership.cpp A strategy adopts and books only orders carrying its own client_order_id prefix. Foreign fills, rejects and cancels never reach its hooks
test_order_request_routing.cpp A connector acts only on its own broker's requests. An order learned from an ack keeps its broker. Cancel-all behaviour with a modify in flight
test_md_subscription.cpp What StrategyManager asks brokers to subscribe: each kind of data per instrument and per broker, one slot per instrument, shared subscriptions sent once and dropped once, ladder holds for MANUAL, slow or stalled connectors, request queue sizing
test_strategy_config_event.cpp StrategyConfigEvent wire format: names and payloads survive intact, long names are truncated and not overrun, updates arrive in order
test_market_maker_quote_slots.cpp The market_maker plugin's quote-slot state machine (it includes the plugin source directly): reprice in place, rejected edits and cancels, tick tolerances, negative books, one cancel per quote on stop
test_order_stacker_config_apply.cpp order_stacker applies config updates on the worker thread, last update wins, a paused strategy stays paused. Built only when the strategy plugins (and so slick-stacker) are part of the build
test_futures_accounting.cpp Contract multiplier in realized and unrealized PnL and order value limits, per-unit fees, zero and negative prices, spreads through zero, enum values and broker ids that must stay stable on the wire
test_spread_fills.cpp Multi-leg fills: the order moves at the spread price while the legs book positions. Replayed fills the strategies already had are dropped
test_position_store.cpp MappedFile and PositionStore: positions and lots survive reopening, slot reuse, full store, lot compaction, files that are not stores are refused, journal progress per broker
test_broker_state_files.cpp The fill journal (numbering, ring behaviour, duplicate refusal, foreign file refusal) and the slot store (reopen, full, foreign session) that out-of-tree order connectors use
test_broker_registry.cpp Every built broker is found by its config name, case-insensitively, duplicates keep the first, a throwing constructor is reported not thrown
test_environment.cpp environment parsing: default, non-string refusal, production aliases, Sim and its two control keys
test_sim_control.cpp The control link to slick-sim: version and feed discovery, status watching and polling, parsing every feed state and field, reply framing across pieces, start-replay rules
test_web_server_http.cpp HTTP and WebSocket answers read off a raw socket: static files, error statuses, order entry refusals, ladder holds and releases, health, sim control, workspaces, non-UTF-8 reasons
test_web_server_shutdown.cpp stop() returns while WebSocket or keep-alive clients are open, sends close frames, is idempotent, and joins a worker whose listen failed
test_workspace_store.cpp Saved window layouts: persistence, defaults, name rules, failed writes, tolerant loading
test_browser_policy.cpp The dashboard origin and the Edge and Chrome URL list policies, with registry writes under a throwaway key on Windows
test_web_setup_script.cpp slick-trader-web.bat run as a user runs it (Windows only)
test_fill_history.cpp The bounded fill history behind GET /api/fills
test_level2_book.cpp The web layer's L2 book and per-browser snapshots: ordering, late subscribers, bounded requests, release of unused books, trade replay
test_mbo_book.cpp Market-by-order books and queue position: what trades ahead, priority order, snapshots, per-instrument books, top of book from MBO
test_instrument_status.cpp An instrument status event reaches a strategy with its reason, and an over-long reason is cut
test_level_book.cpp, test_order_book_publisher.cpp, test_price_scale.cpp, test_polled_link.cpp, test_order_entry.cpp The exchange-neutral building blocks under brokers/common/ that out-of-tree brokers reuse: level aggregation, order-book publishing and chunking, exact price scaling, caller-driven socket links, order entry policies (crossing checks, post-only, whole lots, rate limits, fee lookup)
test_coinbase_definitions.cpp, test_coinbase_order_states.cpp, test_coinbase_trades.cpp Coinbase: product definitions, order state transitions (one ack per status, stale pending acks, modify and cancel once) and trade aggressor sides. Compiled in only when Coinbase is built
test_hyperliquid_definitions.cpp Hyperliquid perp definitions with their size step. Compiled in only when Hyperliquid is built

How broker tests are registered

Broker suites are not in the tests/CMakeLists.txt list. A broker passes them to slick_trader_add_broker(<name> ... TESTS file.cpp), which appends the absolute paths to a global property. tests/CMakeLists.txt reads that property and adds the files to slick-trader-tests. The Coinbase files travel with the Coinbase broker, so a build with SLICK_TRADER_ENABLE_COINBASE=OFF drops them. An out-of-tree broker (SLICK_TRADER_EXTERNAL_BROKERS) brings its tests the same way. The binary links the same broker set as the engine through slick_trader_link_brokers, and each broker adds an interface define SLICK_TRADER_HAS_<NAME> (for example SLICK_TRADER_HAS_COINBASE) that tests can check.

Platform-specific tests

Test Runs on
test_web_server_shutdown.cpp POSIX sockets only. On Windows a single placeholder test reports SKIPPED
test_web_server_http.cpp Linux, macOS and Windows
test_web_setup_script.cpp Windows only. It skips itself when Edge or Chrome is missing
test_browser_policy.cpp The origin tests run everywhere. The registry tests are Windows only, and a non-Windows build checks that add_policy_url fails there
test_order_stacker_config_apply.cpp Only when SLICK_TRADER_BUILD_STRATEGIES is on

The web server tests bind real loopback ports chosen by the OS, and the sim tests listen on one too.

Sanitizer runs

Configure with -DSLICK_TRADER_SANITIZER=address,undefined or thread and run ctest as usual. The CI sanitizers.yml job also sets ASAN_OPTIONS, UBSAN_OPTIONS=halt_on_error=1 and TSAN_OPTIONS=halt_on_error=1. Set them locally to match, otherwise UBSan only warns. See Building.

Writing a test

  1. Add test_<area>.cpp to the slick-trader-tests sources in tests/CMakeLists.txt. For a broker, list it under TESTS in that broker's slick_trader_add_broker() instead.
  2. Use TEST or TEST_F with a name that reads as the behaviour (ARejectedEditDoesNotOrphanTheRestingOrder).
  3. For anything that touches strategies, positions or market data requests, derive from or hold a StrategyManagerFixture, and feed events through process_event().
  4. For a bug fix, write the test first so it fails without the fix, and open the file with a comment that names the bug and the symptom. The existing files read that way.
  5. To assert a warning, create a LogCount("fragment of the format string") before the action and read count() after.
  6. A test that touches a web server picks a port with free_port() and talks through RawClient. Start the server, wait until it accepts, and stop it in TearDown.
  7. Mark anything that cannot run on every platform with #ifdef _WIN32 or a GTEST_SKIP() with a reason.