Internal constructor. `name` is used to identify this context in e.g. log output. This is useful mostly when you have multiple [`TestContext`]s in a test. `log_sender` is assumed to be the sender for a [`LogSink`]. If not supplied a new [`LogSink`] will be created so that events are logged to this test when the [`TestContext`] is dropped.
(name: Option<String>, log_sink: Option<LogSink>)
| 570 | /// [`LogSink`] will be created so that events are logged to this test when the |
| 571 | /// [`TestContext`] is dropped. |
| 572 | async fn new_internal(name: Option<String>, log_sink: Option<LogSink>) -> Self { |
| 573 | let dir = tempdir().unwrap(); |
| 574 | let dbfile = dir.path().join("db.sqlite"); |
| 575 | let id = rand::random(); |
| 576 | if let Some(name) = name { |
| 577 | let mut context_names = CONTEXT_NAMES.write().unwrap(); |
| 578 | context_names.insert(id, name); |
| 579 | } |
| 580 | let events = Events::new(); |
| 581 | let evtracker_receiver = events.get_emitter(); |
| 582 | let ctx = Context::new(&dbfile, id, events, StockStrings::new()) |
| 583 | .await |
| 584 | .expect("failed to create context"); |
| 585 | |
| 586 | let _log_sink = if let Some(log_sink) = log_sink { |
| 587 | // Subscribe existing LogSink and don't store reference to it. |
| 588 | log_sink.subscribe(ctx.get_event_emitter()); |
| 589 | None |
| 590 | } else { |
| 591 | // Create new LogSink and store it inside the `TestContext`. |
| 592 | let log_sink = LogSink::new(); |
| 593 | log_sink.subscribe(ctx.get_event_emitter()); |
| 594 | Some(log_sink) |
| 595 | }; |
| 596 | |
| 597 | ctx.set_config(Config::SkipStartMessages, Some("1")) |
| 598 | .await |
| 599 | .unwrap(); |
| 600 | ctx.set_config(Config::BccSelf, Some("1")).await.unwrap(); |
| 601 | ctx.set_config(Config::SyncMsgs, Some("0")).await.unwrap(); |
| 602 | |
| 603 | Self { |
| 604 | ctx, |
| 605 | dir, |
| 606 | evtracker: EventTracker::new(evtracker_receiver), |
| 607 | _log_sink, |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | /// Sets a name for this [`TestContext`] if one isn't yet set. |
| 612 | /// |
nothing calls this directly
no test coverage detected