Skip to content

Commit 6ad5da2

Browse files
authored
Remove lazy-static in favor of once_cell (#694)
1 parent f828a74 commit 6ad5da2

File tree

10 files changed

+25
-29
lines changed

10 files changed

+25
-29
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ license-file = "LICENSE.txt"
88

99
[workspace.dependencies]
1010
derive_more = { version = "0.99", default-features = false, features = ["constructor", "display", "from", "into"] }
11+
once_cell = "1.16"
1112
tonic = "0.9"
1213
tonic-build = "0.9"
1314
opentelemetry = "0.21"

client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ derive_more = "0.99"
1919
futures = "0.3"
2020
futures-retry = "0.6.0"
2121
http = "0.2"
22-
once_cell = "1.13"
22+
once_cell = { workspace = true }
2323
opentelemetry = { workspace = true, features = ["metrics"] }
2424
parking_lot = "0.12"
2525
prost-types = "0.11"

core/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ governor = "0.6"
4141
http = "0.2"
4242
hyper = "0.14"
4343
itertools = "0.11"
44-
lazy_static = "1.4"
4544
lru = "0.11"
4645
mockall = "0.11"
4746
nix = { version = "0.27", optional = true, features = ["process", "signal"] }
48-
once_cell = "1.5"
47+
once_cell = { workspace = true }
4948
opentelemetry = { workspace = true, features = ["metrics"] }
5049
opentelemetry_sdk = { version = "0.21", features = ["rt-tokio", "metrics"] }
5150
opentelemetry-otlp = { version = "0.14", features = ["tokio", "metrics"] }

core/src/core_tests/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{
1616
Worker,
1717
};
1818
use futures::FutureExt;
19+
use once_cell::sync::Lazy;
1920
use std::time::Duration;
2021
use temporal_sdk_core_api::Worker as WorkerTrait;
2122
use temporal_sdk_core_protos::coresdk::workflow_completion::WorkflowActivationCompletion;
@@ -45,9 +46,8 @@ async fn after_shutdown_server_is_not_polled() {
4546
}
4647

4748
// Better than cloning a billion arcs...
48-
lazy_static::lazy_static! {
49-
static ref BARR: Barrier = Barrier::new(3);
50-
}
49+
static BARR: Lazy<Barrier> = Lazy::new(|| Barrier::new(3));
50+
5151
#[tokio::test]
5252
async fn shutdown_interrupts_both_polls() {
5353
let mut mock_client = mock_manual_workflow_client();

core/src/worker/client/mocks.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use super::*;
22
use futures::Future;
3-
use lazy_static::lazy_static;
3+
use once_cell::sync::Lazy;
44
use std::sync::Arc;
55
use temporal_client::SlotManager;
66

7-
lazy_static! {
8-
pub(crate) static ref DEFAULT_WORKERS_REGISTRY: Arc<SlotManager> = Arc::new(SlotManager::new());
9-
}
7+
static DEFAULT_WORKERS_REGISTRY: Lazy<Arc<SlotManager>> =
8+
Lazy::new(|| Arc::new(SlotManager::new()));
109

1110
pub(crate) static DEFAULT_TEST_CAPABILITIES: &Capabilities = &Capabilities {
1211
signal_and_query_header: true,

core/src/worker/workflow/history_update.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
};
88
use futures::{future::BoxFuture, FutureExt, Stream};
99
use itertools::Itertools;
10+
use once_cell::sync::Lazy;
1011
use std::{
1112
collections::VecDeque,
1213
fmt::Debug,
@@ -23,12 +24,11 @@ use temporal_sdk_core_protos::temporal::api::{
2324
};
2425
use tracing::Instrument;
2526

26-
lazy_static::lazy_static! {
27-
static ref EMPTY_FETCH_ERR: tonic::Status
28-
= tonic::Status::unknown("Fetched empty history page");
29-
static ref EMPTY_TASK_ERR: tonic::Status
30-
= tonic::Status::unknown("Received an empty workflow task with no queries or history");
31-
}
27+
static EMPTY_FETCH_ERR: Lazy<tonic::Status> =
28+
Lazy::new(|| tonic::Status::unknown("Fetched empty history page"));
29+
static EMPTY_TASK_ERR: Lazy<tonic::Status> = Lazy::new(|| {
30+
tonic::Status::unknown("Received an empty workflow task with no queries or history")
31+
});
3232

3333
/// Represents one or more complete WFT sequences. History events are expected to be consumed from
3434
/// it and applied to the state machines via [HistoryUpdate::take_next_wft_sequence]

core/src/worker/workflow/machines/transition_coverage.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! never ever be removed from behind `#[cfg(test)]` compilation.
55
66
use dashmap::{mapref::entry::Entry, DashMap, DashSet};
7+
use once_cell::sync::Lazy;
78
use std::{
89
path::PathBuf,
910
sync::{
@@ -15,13 +16,11 @@ use std::{
1516
};
1617

1718
// During test we want to know about which transitions we've covered in state machines
18-
lazy_static::lazy_static! {
19-
static ref COVERED_TRANSITIONS: DashMap<String, DashSet<CoveredTransition>>
20-
= DashMap::new();
21-
static ref COVERAGE_SENDER: SyncSender<(String, CoveredTransition)> =
22-
spawn_save_coverage_at_end();
23-
static ref THREAD_HANDLE: Mutex<Option<JoinHandle<()>>> = Mutex::new(None);
24-
}
19+
static COVERED_TRANSITIONS: Lazy<DashMap<String, DashSet<CoveredTransition>>> =
20+
Lazy::new(DashMap::new);
21+
static COVERAGE_SENDER: Lazy<SyncSender<(String, CoveredTransition)>> =
22+
Lazy::new(spawn_save_coverage_at_end);
23+
static THREAD_HANDLE: Lazy<Mutex<Option<JoinHandle<()>>>> = Lazy::new(|| Mutex::new(None));
2524

2625
#[derive(Eq, PartialEq, Hash, Debug)]
2726
struct CoveredTransition {

sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ base64 = "0.21"
2020
crossbeam-channel = "0.5"
2121
derive_more = { workspace = true }
2222
futures = "0.3"
23-
once_cell = "1.10"
23+
once_cell = { workspace = true }
2424
parking_lot = { version = "0.12", features = ["send_guard"] }
2525
prost-types = { version = "0.4", package = "prost-wkt-types" }
2626
sha2 = "0.10"

test-utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ base64 = "0.21"
2020
bytes = "1.3"
2121
futures = "0.3"
2222
log = "0.4"
23-
once_cell = "1.16"
23+
once_cell = { workspace = true }
2424
parking_lot = "0.12"
2525
prost = "0.11"
2626
prost-types = "0.11"

tests/integ_tests/update_tests.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::{anyhow, bail};
22
use assert_matches::assert_matches;
33
use futures_util::{future, future::join_all, StreamExt};
4-
use lazy_static::lazy_static;
4+
use once_cell::sync::Lazy;
55
use std::{
66
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
77
time::Duration,
@@ -817,9 +817,7 @@ async fn worker_restarted_in_middle_of_update() {
817817
let mut worker = starter.worker().await;
818818
let client = starter.get_client().await;
819819

820-
lazy_static! {
821-
static ref BARR: Barrier = Barrier::new(2);
822-
}
820+
static BARR: Lazy<Barrier> = Lazy::new(|| Barrier::new(2));
823821
static ACT_RAN: AtomicBool = AtomicBool::new(false);
824822
worker.register_wf(wf_name.to_owned(), |ctx: WfContext| async move {
825823
ctx.update_handler(

0 commit comments

Comments
 (0)