|
15 | 15 |
|
16 | 16 | use std::time::Duration;
|
17 | 17 |
|
18 |
| -use pegasus::api::{Collect, IterCondition, Iteration, Map, Sink}; |
| 18 | +use pegasus::api::{Collect, HasAny, IterCondition, Iteration, Map, Sink}; |
19 | 19 | use pegasus::JobConf;
|
20 | 20 |
|
| 21 | +static CORE_POOL_SIZE: &'static str = "PEGASUS_CORE_POOL_SIZE"; |
| 22 | + |
21 | 23 | /// test binary merge pipeline;
|
22 | 24 | #[test]
|
23 | 25 | fn timeout_test_01() {
|
@@ -133,3 +135,60 @@ fn timeout_resubmit_test() {
|
133 | 135 | result.sort();
|
134 | 136 | assert_eq!(result, [20, 20]);
|
135 | 137 | }
|
| 138 | + |
| 139 | +#[test] |
| 140 | +fn timeout_caused_by_large_job() { |
| 141 | + let core = ::std::env::var(CORE_POOL_SIZE) |
| 142 | + .map(|value| { |
| 143 | + value |
| 144 | + .parse::<usize>() |
| 145 | + .unwrap_or_else(|_| num_cpus::get()) |
| 146 | + }) |
| 147 | + .unwrap_or_else(|_| num_cpus::get()); |
| 148 | + let mut conf_1 = JobConf::new("test"); |
| 149 | + conf_1.time_limit = 5000; |
| 150 | + conf_1.set_workers(core as u32); |
| 151 | + let mut conf_2 = JobConf::new("block_job"); |
| 152 | + conf_2.set_workers(core as u32); |
| 153 | + let mut results_1 = pegasus::run(conf_1, || { |
| 154 | + |input, output| { |
| 155 | + let worker_id = input.get_worker_index(); |
| 156 | + input |
| 157 | + .input_from(vec![0u32])? |
| 158 | + .map(move |i| { |
| 159 | + if worker_id != 0 { |
| 160 | + std::thread::sleep(Duration::from_millis(3000)); |
| 161 | + } |
| 162 | + Ok(i) |
| 163 | + })? |
| 164 | + .any()? |
| 165 | + .sink_into(output) |
| 166 | + } |
| 167 | + }) |
| 168 | + .expect("submit job failure;"); |
| 169 | + let _ = pegasus::run(conf_2, || { |
| 170 | + |input, output| { |
| 171 | + let worker_id = input.get_worker_index(); |
| 172 | + input |
| 173 | + .input_from(vec![0u32])? |
| 174 | + .map(|i| { |
| 175 | + std::thread::sleep(Duration::from_millis(4000)); |
| 176 | + Ok(i) |
| 177 | + })? |
| 178 | + .any()? |
| 179 | + .sink_into(output) |
| 180 | + } |
| 181 | + }) |
| 182 | + .expect("submit job failure;"); |
| 183 | + let mut count = 0; |
| 184 | + while let Some(result) = results_1.next() { |
| 185 | + if let Ok(data) = result { |
| 186 | + count += 1; |
| 187 | + } else { |
| 188 | + let err = result.err().unwrap(); |
| 189 | + assert_eq!(err.to_string(), "Job is canceled;".to_string()); |
| 190 | + break; |
| 191 | + } |
| 192 | + } |
| 193 | + assert!(!results_1.is_cancel()); |
| 194 | +} |
0 commit comments