Skip to content

Commit 0f43df9

Browse files
committed
Auto merge of #705 - Mark-Simulacrum:no-state, r=Mark-Simulacrum
Remove RunnerState Store logs into a local stack variable that gets uploaded at the end. There's no reason to keep them in a semi-global place, and this makes it easier to capture more into the logs (e.g., should make us include retry logs automatically).
2 parents afd8d32 + 5715bd3 commit 0f43df9

File tree

8 files changed

+46
-141
lines changed

8 files changed

+46
-141
lines changed

src/agent/results.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::agent::api::AgentApi;
2-
use crate::config::Config;
32
use crate::crates::Crate;
43
use crate::experiments::Experiment;
54
use crate::prelude::*;
@@ -48,16 +47,14 @@ impl<'a> WriteResults for ResultsUploader<'a> {
4847
ex: &Experiment,
4948
toolchain: &Toolchain,
5049
krate: &Crate,
51-
existing_logs: Option<LogStorage>,
52-
config: &Config,
50+
storage: &LogStorage,
5351
_: EncodingType,
5452
f: F,
5553
) -> Fallible<TestResult>
5654
where
5755
F: FnOnce() -> Fallible<TestResult>,
5856
{
59-
let storage = existing_logs.unwrap_or_else(|| LogStorage::from(config));
60-
let result = logging::capture(&storage, f)?;
57+
let result = logging::capture(storage, f)?;
6158
let output = storage.to_string();
6259

6360
let mut updated = None;

src/report/archives.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ mod tests {
190190
use crate::results::{DatabaseDB, EncodingType, FailureReason, TestResult, WriteResults};
191191
use flate2::read::GzDecoder;
192192
use mime::Mime;
193+
use rustwide::logging::LogStorage;
193194
use std::io::Read;
194195
use tar::Archive;
195196

@@ -217,8 +218,7 @@ mod tests {
217218
&ex,
218219
&ex.toolchains[0],
219220
crate1,
220-
None,
221-
&config,
221+
&LogStorage::from(&config),
222222
EncodingType::Gzip,
223223
|| {
224224
info!("tc1 crate1");
@@ -231,8 +231,7 @@ mod tests {
231231
&ex,
232232
&ex.toolchains[1],
233233
crate1,
234-
None,
235-
&config,
234+
&LogStorage::from(&config),
236235
EncodingType::Plain,
237236
|| {
238237
info!("tc2 crate1");
@@ -245,8 +244,7 @@ mod tests {
245244
&ex,
246245
&ex.toolchains[0],
247246
crate2,
248-
None,
249-
&config,
247+
&LogStorage::from(&config),
250248
EncodingType::Gzip,
251249
|| {
252250
info!("tc1 crate2");
@@ -259,8 +257,7 @@ mod tests {
259257
&ex,
260258
&ex.toolchains[1],
261259
crate2,
262-
None,
263-
&config,
260+
&LogStorage::from(&config),
264261
EncodingType::Plain,
265262
|| {
266263
info!("tc2 crate2");

src/results/db.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::config::Config;
21
use crate::crates::Crate;
32
use crate::db::{Database, QueryUtils};
43
use crate::experiments::{Experiment, Status};
@@ -224,16 +223,14 @@ impl<'a> WriteResults for DatabaseDB<'a> {
224223
ex: &Experiment,
225224
toolchain: &Toolchain,
226225
krate: &Crate,
227-
existing_logs: Option<LogStorage>,
228-
config: &Config,
226+
storage: &LogStorage,
229227
encoding_type: EncodingType,
230228
f: F,
231229
) -> Fallible<TestResult>
232230
where
233231
F: FnOnce() -> Fallible<TestResult>,
234232
{
235-
let storage = existing_logs.unwrap_or_else(|| LogStorage::from(config));
236-
let result = logging::capture(&storage, f)?;
233+
let result = logging::capture(storage, f)?;
237234
let output = storage.to_string();
238235
self.store_result(
239236
ex,
@@ -266,6 +263,7 @@ impl<'a> DeleteResults for DatabaseDB<'a> {
266263
#[cfg(test)]
267264
mod tests {
268265
use base64::Engine;
266+
use rustwide::logging::LogStorage;
269267

270268
use super::{DatabaseDB, ProgressData, TaskResult};
271269
use crate::actions::{Action, ActionsCtx, CreateExperiment};
@@ -360,8 +358,7 @@ mod tests {
360358
&ex,
361359
&MAIN_TOOLCHAIN,
362360
&krate,
363-
None,
364-
&config,
361+
&LogStorage::from(&config),
365362
EncodingType::Plain,
366363
|| {
367364
info!("hello world");
@@ -408,8 +405,7 @@ mod tests {
408405
&ex,
409406
&TEST_TOOLCHAIN,
410407
&krate,
411-
None,
412-
&config,
408+
&LogStorage::from(&config),
413409
EncodingType::Plain,
414410
|| {
415411
info!("Another log message!");

src/results/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod db;
22
#[cfg(test)]
33
mod dummy;
4-
use crate::config::Config;
54
use crate::crates::Crate;
65
use crate::experiments::Experiment;
76
use crate::prelude::*;
@@ -45,8 +44,7 @@ pub trait WriteResults {
4544
ex: &Experiment,
4645
toolchain: &Toolchain,
4746
krate: &Crate,
48-
existing_logs: Option<LogStorage>,
49-
config: &Config,
47+
existing_logs: &LogStorage,
5048
encoding_type: EncodingType,
5149
f: F,
5250
) -> Fallible<TestResult>

src/runner/mod.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ use crate::experiments::{Experiment, Mode};
99
use crate::prelude::*;
1010
use crate::results::{TestResult, WriteResults};
1111
use crate::runner::worker::{DiskSpaceWatcher, Worker};
12-
use rustwide::logging::LogStorage;
1312
use rustwide::Workspace;
14-
use std::collections::HashMap;
15-
use std::sync::Mutex;
1613
use std::thread::scope;
1714
use std::time::Duration;
1815

@@ -23,28 +20,6 @@ const DISK_SPACE_WATCHER_THRESHOLD: f32 = 0.80;
2320
#[error("overridden task result to {0}")]
2421
pub struct OverrideResult(TestResult);
2522

26-
struct RunnerStateInner {
27-
prepare_logs: HashMap<Crate, LogStorage>,
28-
}
29-
30-
struct RunnerState {
31-
inner: Mutex<RunnerStateInner>,
32-
}
33-
34-
impl RunnerState {
35-
fn new() -> Self {
36-
RunnerState {
37-
inner: Mutex::new(RunnerStateInner {
38-
prepare_logs: HashMap::new(),
39-
}),
40-
}
41-
}
42-
43-
fn lock(&self) -> std::sync::MutexGuard<RunnerStateInner> {
44-
self.inner.lock().unwrap()
45-
}
46-
}
47-
4823
pub fn run_ex<DB: WriteResults + Sync>(
4924
ex: &Experiment,
5025
workspace: &Workspace,
@@ -106,19 +81,8 @@ pub fn run_ex<DB: WriteResults + Sync>(
10681

10782
info!("running tasks in {} threads...", threads_count);
10883

109-
let state = RunnerState::new();
11084
let workers = (0..threads_count)
111-
.map(|i| {
112-
Worker::new(
113-
format!("worker-{i}"),
114-
workspace,
115-
ex,
116-
config,
117-
&state,
118-
db,
119-
next_crate,
120-
)
121-
})
85+
.map(|i| Worker::new(format!("worker-{i}"), workspace, ex, config, db, next_crate))
12286
.collect::<Vec<_>>();
12387

12488
let disk_watcher = DiskSpaceWatcher::new(

src/runner/tasks.rs

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::crates::{Crate, GitHubRepo};
33
use crate::experiments::Experiment;
44
use crate::prelude::*;
55
use crate::results::{EncodingType, TestResult, WriteResults};
6+
use crate::runner::test;
67
use crate::runner::test::detect_broken;
7-
use crate::runner::{test, RunnerState};
88
use crate::toolchain::Toolchain;
99
use crate::utils;
1010
use rustwide::{Build, BuildDirectory, Workspace};
@@ -21,7 +21,6 @@ pub(super) struct TaskCtx<'ctx, DB: WriteResults + 'ctx> {
2121
pub(super) experiment: &'ctx Experiment,
2222
pub(super) toolchain: &'ctx Toolchain,
2323
pub(super) krate: &'ctx Crate,
24-
pub(super) state: &'ctx RunnerState,
2524
pub(super) quiet: bool,
2625
}
2726

@@ -33,7 +32,6 @@ impl<'ctx, DB: WriteResults + 'ctx> TaskCtx<'ctx, DB> {
3332
experiment: &'ctx Experiment,
3433
toolchain: &'ctx Toolchain,
3534
krate: &'ctx Crate,
36-
state: &'ctx RunnerState,
3735
quiet: bool,
3836
) -> Self {
3937
TaskCtx {
@@ -43,7 +41,6 @@ impl<'ctx, DB: WriteResults + 'ctx> TaskCtx<'ctx, DB> {
4341
experiment,
4442
toolchain,
4543
krate,
46-
state,
4744
quiet,
4845
}
4946
}
@@ -102,10 +99,9 @@ impl Task {
10299
&self,
103100
ex: &Experiment,
104101
db: &DB,
105-
state: &RunnerState,
106-
config: &Config,
107102
err: &failure::Error,
108103
result: &TestResult,
104+
storage: &LogStorage,
109105
) -> Fallible<()> {
110106
match self.step {
111107
TaskStep::Prepare | TaskStep::Cleanup => {}
@@ -116,24 +112,11 @@ impl Task {
116112
| TaskStep::Clippy { ref tc, .. }
117113
| TaskStep::Rustdoc { ref tc, .. }
118114
| TaskStep::UnstableFeatures { ref tc } => {
119-
let log_storage = state
120-
.lock()
121-
.prepare_logs
122-
.get(&self.krate)
123-
.map(|s| s.duplicate());
124-
db.record_result(
125-
ex,
126-
tc,
127-
&self.krate,
128-
log_storage,
129-
config,
130-
EncodingType::Plain,
131-
|| {
132-
error!("this task or one of its parent failed!");
133-
utils::report_failure(err);
134-
Ok(result.clone())
135-
},
136-
)?;
115+
db.record_result(ex, tc, &self.krate, storage, EncodingType::Plain, || {
116+
error!("this task or one of its parent failed!");
117+
utils::report_failure(err);
118+
Ok(result.clone())
119+
})?;
137120
}
138121
}
139122

@@ -147,7 +130,7 @@ impl Task {
147130
build_dir: &'ctx HashMap<&'ctx crate::toolchain::Toolchain, Mutex<BuildDirectory>>,
148131
ex: &'ctx Experiment,
149132
db: &'ctx DB,
150-
state: &'ctx RunnerState,
133+
logs: &LogStorage,
151134
) -> Fallible<()> {
152135
let (build_dir, action, test, toolchain, quiet): (
153136
_,
@@ -184,22 +167,16 @@ impl Task {
184167
),
185168
TaskStep::Cleanup => {
186169
// Remove stored logs
187-
state.lock().prepare_logs.remove(&self.krate);
188170
return Ok(());
189171
}
190172
TaskStep::Prepare => {
191-
let storage = LogStorage::from(config);
192-
state
193-
.lock()
194-
.prepare_logs
195-
.insert(self.krate.clone(), storage.clone());
196-
logging::capture(&storage, || {
173+
logging::capture(logs, || {
197174
let rustwide_crate = self.krate.to_rustwide();
198175
for attempt in 1..=15 {
199176
match detect_broken(rustwide_crate.fetch(workspace)) {
200177
Ok(()) => break,
201178
Err(e) => {
202-
if storage.to_string().contains("No space left on device") {
179+
if logs.to_string().contains("No space left on device") {
203180
if attempt == 15 {
204181
// If we've failed 15 times, then
205182
// just give up. It's been at least
@@ -256,33 +233,16 @@ impl Task {
256233
// If a skipped crate is somehow sent to the agent (for example, when a crate was
257234
// added to the experiment and *then* blacklisted) report the crate as skipped
258235
// instead of silently ignoring it.
259-
db.record_result(
260-
ex,
261-
tc,
262-
&self.krate,
263-
None,
264-
config,
265-
EncodingType::Plain,
266-
|| {
267-
warn!("crate skipped");
268-
Ok(TestResult::Skipped)
269-
},
270-
)?;
236+
db.record_result(ex, tc, &self.krate, logs, EncodingType::Plain, || {
237+
warn!("crate skipped");
238+
Ok(TestResult::Skipped)
239+
})?;
271240
return Ok(());
272241
}
273242
};
274243

275-
let ctx = TaskCtx::new(
276-
build_dir,
277-
config,
278-
db,
279-
ex,
280-
toolchain,
281-
&self.krate,
282-
state,
283-
quiet,
284-
);
285-
test::run_test(action, &ctx, test)?;
244+
let ctx = TaskCtx::new(build_dir, config, db, ex, toolchain, &self.krate, quiet);
245+
test::run_test(action, &ctx, test, logs)?;
286246

287247
Ok(())
288248
}

src/runner/test.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use docsrs_metadata::Metadata as DocsrsMetadata;
1010
use failure::Error;
1111
use remove_dir_all::remove_dir_all;
1212
use rustwide::cmd::{CommandError, ProcessLinesActions, SandboxBuilder};
13+
use rustwide::logging::LogStorage;
1314
use rustwide::{Build, PrepareError};
1415
use std::collections::{BTreeSet, HashMap, HashSet};
1516
use std::convert::TryFrom;
@@ -215,25 +216,19 @@ pub(super) fn run_test<DB: WriteResults>(
215216
action: &str,
216217
ctx: &TaskCtx<DB>,
217218
test_fn: fn(&TaskCtx<DB>, &Build, &[Package]) -> Fallible<TestResult>,
219+
logs: &LogStorage,
218220
) -> Fallible<()> {
219221
if let Some(res) = ctx
220222
.db
221223
.get_result(ctx.experiment, ctx.toolchain, ctx.krate)?
222224
{
223225
info!("skipping crate {}. existing result: {}", ctx.krate, res);
224226
} else {
225-
let log_storage = ctx
226-
.state
227-
.lock()
228-
.prepare_logs
229-
.get(ctx.krate)
230-
.map(|s| s.duplicate());
231227
ctx.db.record_result(
232228
ctx.experiment,
233229
ctx.toolchain,
234230
ctx.krate,
235-
log_storage,
236-
ctx.config,
231+
logs,
237232
EncodingType::Plain,
238233
|| {
239234
info!(

0 commit comments

Comments
 (0)