From bcfd6c2d3ab84d16d6a7ee5790a569d967d09f4f Mon Sep 17 00:00:00 2001 From: Peter Goodspeed-Niklaus Date: Tue, 28 Jul 2020 22:18:54 +0200 Subject: [PATCH] add simple name derivation heuristic for JobManager Subsystem impl (#1490) Subsystems are encouraged to either typedef themselves as appropriate `JobManager` instances for their job type, or wrap a `JobManager` instance and delegate the `Subsystem` impl. In both cases, we want to use a sensible, non-repeated subsystem name for appropriate logging and debugging. This PR adds a heuristic: if the job name ends in the literal "Job", then that gets stripped. Otherwise, the job name is used. This improves on the previous situation, in which subsystems typedef'd to or wrapping `JobManager` all got the same constant (!) name. --- polkadot/node/subsystem/src/util.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/polkadot/node/subsystem/src/util.rs b/polkadot/node/subsystem/src/util.rs index ce31bebeda..440fda08f0 100644 --- a/polkadot/node/subsystem/src/util.rs +++ b/polkadot/node/subsystem/src/util.rs @@ -715,7 +715,7 @@ where }); SpawnedSubsystem { - name: "JobManager", + name: Job::NAME.strip_suffix("Job").unwrap_or(Job::NAME), future, } } @@ -737,6 +737,8 @@ mod tests { ActiveLeavesUpdate, FromOverseer, OverseerSignal, + SpawnedSubsystem, + Subsystem, }; use futures::{ channel::mpsc, @@ -959,4 +961,16 @@ mod tests { ); }); } + + #[test] + fn test_subsystem_impl_and_name_derivation() { + let pool = sp_core::testing::TaskExecutor::new(); + let (context, _) = make_subsystem_context::(pool.clone()); + + let SpawnedSubsystem { name, .. } = FakeCandidateSelectionSubsystem::new( + pool, + HashMap::new(), + ).start(context); + assert_eq!(name, "FakeCandidateSelection"); + } }