Skip to content

Add HostedStoreContext harness for IHost + AddMarten tests - #5102

Merged
jeremydmiller merged 1 commit into
masterfrom
test/hosted-store-context
Aug 1, 2026
Merged

Add HostedStoreContext harness for IHost + AddMarten tests#5102
jeremydmiller merged 1 commit into
masterfrom
test/hosted-store-context

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Phase 2 (continued) of the test-harness standardization program (HANDOFF-test-harness-standardization.md): a shared harness for the ~37 event-sourcing test files that inline Host.CreateDefaultBuilder + AddMarten + StartAsync with hard-coded schema literals.

The harness

Marten.Testing/Harness/HostedStoreContext:

  • StartHostAsync(configure, daemonMode?, configureServices?, configureMarten?) — main store pre-wired with the test connection string, a per-class schema name (same convention as OneOffConfigurationsContext), and DisableNpgsqlLogging. daemonMode maps to AddAsyncDaemon; configureMarten receives the AddMarten fluent expression (ApplyAllDatabaseChangesOnStartup etc.); configureServices covers ancillary AddMartenStore<T> registrations.
  • Every started host is tracked and stopped + disposed newest-first at class teardown — several of the old inline blocks never stopped their hosts at all.
  • Linked into EventSourcingTests.csproj; other projects opt in by adding the Compile link when they migrate.

First six migrations (proof of shape)

determining_the_event_store_identity, propagate_logger_to_projections, generating_event_store_descriptors, Bug_4441_force_catch_up_with_outbox, Bug_4904_force_catch_up_under_externally_managed, ancillary_store_enrichment_tests — retiring ~10 hard-coded schema literals. All 9 tests across the six files pass on net9.0.

Deliberately untouched: Examples/* + testing_projections.cs (the inline host is the published doc sample), and Daemon/postgres_listen_notify_wakeup_tests.cs (uncommitted #4961 work in flight on that file). The remaining inline-host files in DaemonTests/TPE are follow-up material; DaemonTests' DaemonContext host helpers (hard-wired to TripProjectionWithCustomName) can be reimplemented on this base in a later pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01U99pVx6kXwiGmaBUGLv7jB

Phase 2 of the test-harness standardization program: tests that need a real
IHost (daemon coordination, DI-registered projections, ancillary stores) had
no shared harness — 37 files across the event sourcing projects inline the
same Host.CreateDefaultBuilder + AddMarten + StartAsync block with hard-coded
schema literals, and the only prior factoring (DaemonContext's host helpers)
is hard-wired to one specific projection.

Marten.Testing/Harness/HostedStoreContext owns host lifetime (hosts stopped
and disposed newest-first at class teardown) and pre-configures the main
store with the test connection string, a per-class schema name, and Npgsql
logging disabled. StartHostAsync exposes the daemon mode, the AddMarten
fluent expression (for chained calls like ApplyAllDatabaseChangesOnStartup),
and an IServiceCollection hook for ancillary AddMartenStore registrations.

First six EventSourcingTests files migrated, retiring seven hard-coded
schema literals (es_identity, things, system_part, capabilities,
descriptor_enrichment, max_seq_usage, bug4441_default, bug4441_outbox,
bug4904_externally_managed, ancillary_enrich_*):

- determining_the_event_store_identity
- propagate_logger_to_projections
- generating_event_store_descriptors
- Bugs/Bug_4441_force_catch_up_with_outbox
- Bugs/Bug_4904_force_catch_up_under_externally_managed
- Aggregation/ancillary_store_enrichment_tests

Deliberately untouched: Examples/* and Projections/testing_projections.cs
(doc snippets where the inline host IS the sample), and
Daemon/postgres_listen_notify_wakeup_tests.cs (open work in flight on that
file for #4961).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U99pVx6kXwiGmaBUGLv7jB
@jeremydmiller
jeremydmiller merged commit 15b1adc into master Aug 1, 2026
10 checks passed
@jeremydmiller
jeremydmiller deleted the test/hosted-store-context branch August 1, 2026 14:16
jeremydmiller added a commit that referenced this pull request Aug 1, 2026
Continues the phase-2 harness standardization (#5098-#5103): the DaemonTests
side of the inline Host.CreateDefaultBuilder + AddMarten pattern moves onto
the shared HostedStoreContext harness from #5102, retiring nine hard-coded
schema literals (bug2073, bug3059, coordinator, missing_events,
subscriptions_start, ioc, bluegreen, feature_4284_net*, eao_*) in favor of
per-class schema names, and letting the harness own host lifetime.

Migrated:
- Bugs/Bug_2073_tenancy_problems
- Bugs/Bug_3059_double_application
- Composites/Feature_4284_composite_projection_with_services
- Internals/pausing_and_resuming_the_daemon
- Resiliency/skipping_unknown_event_types_in_continuous_builds (also fixes
  the NRE in DisposeAsync when a test failed before _processor was assigned)
- Subscriptions/subscribe_from_present
- Subscriptions/subscriptions_end_to_end: the five host-based tests split out
  of the OneOffConfigurationsContext class into a new
  subscription_registrations_through_host: HostedStoreContext class;
  subscriptions_are_part_of_the_event_store_usage keeps a hand-rolled host
  because it asserts exactly one IEventStore registration and the harness's
  main store would add a second
- EventSourcingTests/event_append_observation (per-test schema suffixes now
  derive from SchemaName)
- DaemonTests.ManualOnly/Coordination/blue_green_projection_deployments

Also fixes a latent ManualOnly breakage: BlueProjection/GreenProjection use
conventional Apply methods but were not declared partial, so 4 of the 5
blue/green tests failed on master with "No source-generated dispatcher
found". Both are partial now and all 5 pass.

Deliberately untouched: Internals/service_registrations (Build()-only Lamar
container assertions, no started host), Bug_3080 +
MultiTenancy/dynamic_spin_up_of_dynamic_tenants + multi_tenancy_by_database
(real multi-database provisioning that does not fit the single-connection
harness), Examples/* and Projections/testing_projections.cs (doc snippets),
Daemon/postgres_listen_notify_wakeup_tests.cs (#4961 in flight), and the four
TenantPartitionedEventsTests multi-node host files (follow-up).

net9.0: DaemonTests 260/260, EventSourcingTests event_append_observation 8/8,
ManualOnly blue_green 5/5.


Claude-Session: https://claude.ai/code/session_01U99pVx6kXwiGmaBUGLv7jB

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant