Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
- remove JobTrait::Subsystem
- fix tests

Signed-off-by: Andrei Sandu <[email protected]>
  • Loading branch information
sandreim committed Nov 10, 2021
1 parent 5fd25dd commit dae09bc
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 24 deletions.
1 change: 0 additions & 1 deletion node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,6 @@ impl util::JobTrait for CandidateBackingJob {
type Metrics = Metrics;

const NAME: &'static str = "candidate-backing-job";
const SUBSYSTEM: &'static str = "candidate-backing";

fn run<S: SubsystemSender>(
parent: Hash,
Expand Down
1 change: 0 additions & 1 deletion node/core/bitfield-signing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ impl JobTrait for BitfieldSigningJob {
type Metrics = Metrics;

const NAME: &'static str = "bitfield-signing-job";
const SUBSYSTEM: &'static str = "bitfield-signing";

/// Run a job for the parent block indicated
fn run<S: SubsystemSender>(
Expand Down
3 changes: 1 addition & 2 deletions node/core/provisioner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ impl JobTrait for ProvisioningJob {
type RunArgs = ();
type Metrics = Metrics;

const NAME: &'static str = "provisioning-job";
const SUBSYSTEM: &'static str = "provisioner";
const NAME: &'static str = "provisioner-job";

/// Run a job for the parent block indicated
//
Expand Down
6 changes: 4 additions & 2 deletions node/core/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ where
)
}
} else {
self.spawn_handle.spawn_blocking(API_REQUEST_TASK_NAME, None, request);
self.spawn_handle
.spawn_blocking(API_REQUEST_TASK_NAME, Some("runtime-api"), request);
self.active_requests.push(receiver);
}
}
Expand All @@ -288,7 +289,8 @@ where
}

if let Some((req, recv)) = self.waiting_requests.pop_front() {
self.spawn_handle.spawn_blocking(API_REQUEST_TASK_NAME, None, req);
self.spawn_handle
.spawn_blocking(API_REQUEST_TASK_NAME, Some("runtime-api"), req);
self.active_requests.push(recv);
}
}
Expand Down
4 changes: 2 additions & 2 deletions node/network/availability-distribution/src/tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl TestState {
let update_tx = tx.clone();
harness.pool.spawn(
"sending-active-leaves-updates",
"",
None,
async move {
for update in updates {
overseer_signal(update_tx.clone(), OverseerSignal::ActiveLeaves(update)).await;
Expand Down Expand Up @@ -310,7 +310,7 @@ fn to_incoming_req(
oneshot::channel();
executor.spawn(
"message-forwarding",
"",
None,
async {
let response = rx.await;
let payload = response.expect("Unexpected canceled request").result;
Expand Down
12 changes: 6 additions & 6 deletions node/overseer/overseer-gen/examples/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,20 @@ struct DummySpawner;
impl SpawnNamed for DummySpawner {
fn spawn_blocking(
&self,
_task_name: &'static str,
_subsystem_name: &'static str,
task_name: &'static str,
subsystem_name: Option<&'static str>,
_future: futures::future::BoxFuture<'static, ()>,
) {
unimplemented!("spawn blocking {}", name)
unimplemented!("spawn blocking {} {}", task_name, subsystem_name.unwrap_or("default"))
}

fn spawn(
&self,
_task_name: &'static str,
_subsystem_name: &'static str,
task_name: &'static str,
subsystem_name: Option<&'static str>,
_future: futures::future::BoxFuture<'static, ()>,
) {
unimplemented!("spawn {}", name)
unimplemented!("spawn {} {}", task_name, subsystem_name.unwrap_or("default"))
}
}

Expand Down
13 changes: 7 additions & 6 deletions node/subsystem-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,9 @@ pub trait JobTrait: Unpin + Sized {
/// The `delegate_subsystem!` macro should take care of this.
type Metrics: 'static + metrics::Metrics + Send;

/// Name of the job, i.e. `CandidateBackingJob`
/// Name of the job, i.e. `candidate-backing-job`
const NAME: &'static str;

/// Name of the subsystem that spawned the job , i.e. `approval_distribution`
const SUBSYSTEM: &'static str;

/// Run a job for the given relay `parent`.
///
/// The job should be ended when `receiver` returns `None`.
Expand Down Expand Up @@ -580,7 +577,11 @@ where
Ok(())
});

self.spawner.spawn(Job::NAME, Some(Job::SUBSYSTEM), future.map(drop).boxed());
self.spawner.spawn(
Job::NAME,
Some(Job::NAME.strip_suffix("-job").unwrap_or(Job::NAME)),
future.map(drop).boxed(),
);
self.outgoing_msgs.push(from_job_rx);

let handle = JobHandle { _abort_handle: AbortOnDrop(abort_handle), to_job: to_job_tx };
Expand Down Expand Up @@ -753,6 +754,6 @@ where
Ok(())
});

SpawnedSubsystem { name: Job::NAME.strip_suffix("Job").unwrap_or(Job::NAME), future }
SpawnedSubsystem { name: Job::NAME.strip_suffix("-job").unwrap_or(Job::NAME), future }
}
}
5 changes: 2 additions & 3 deletions node/subsystem-util/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ impl JobTrait for FakeCollatorProtocolJob {
type RunArgs = bool;
type Metrics = ();

const NAME: &'static str = "FakeCollatorProtocolJob";
const SUBSYSTEM: &'static str = "fake_collator";
const NAME: &'static str = "fake-collator-protocol-job";

/// Run a job for the parent block indicated
//
Expand Down Expand Up @@ -200,7 +199,7 @@ fn test_subsystem_impl_and_name_derivation() {

let SpawnedSubsystem { name, .. } =
FakeCollatorProtocolSubsystem::new(pool, false, ()).start(context);
assert_eq!(name, "FakeCollatorProtocol");
assert_eq!(name, "fake-collator-protocol");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion parachain/test-parachains/adder/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl Collator {
let seconded_collations = seconded_collations.clone();
spawner.spawn(
"adder-collator-seconded",
"",
None,
async move {
if let Ok(res) = recv.await {
if !matches!(
Expand Down

0 comments on commit dae09bc

Please sign in to comment.