Skip to content

Commit f5a039f

Browse files
committed
src/lib.rs:fn wait: add to tests
1 parent d036e39 commit f5a039f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ pub fn run(args: Args) -> Result<()> {
178178
// a - b
179179
// }
180180

181+
pub fn wait(){
182+
use std::process::Command;
183+
let mut child = Command::new("sleep").arg("5").spawn().unwrap();
184+
let _result = child.wait().unwrap();
185+
let _result = child.wait().unwrap();
186+
}
187+
181188
#[cfg(test)]
182189
mod tests {
183190
// Note this useful idiom: importing names from outer (for mod tests) scope.
@@ -192,18 +199,21 @@ mod tests {
192199
let binding = format!("v1/difficulty-adjustment").clone();
193200
let difficulty_adjustment: &str = blocking(&binding).expect("REASON");
194201
let difficulty_adjustment = generic_sys_call("difficulty_adjustment", "extraneous_arg");
202+
wait();
195203
}
196204
#[test]
197205
fn test_price(){
198206
// GET /api/v1/prices
199207
let binding = format!("v1/prices").clone();
200208
let prices: &str = blocking(&binding).expect("REASON");
209+
wait();
201210
}
202211
#[test]
203212
fn test_historical_price() {
204213
// GET /api/v1/historical-price?currency=EUR&timestamp=1500000000
205214
let historical_price_json = historical_price(&"EUR", &"1500000000");
206215
print!("\n{{\"prices\":[{{\"time\":1499904000,\"EUR\":1964,\"USD\":2254.9}}],\"exchangeRates\":{{\"USDEUR\":0.92,\"USDGBP\":0.78,\"USDCAD\":1.38,\"USDCHF\":0.87,\"USDAUD\":1.53,\"USDJPY\":146.62}}}}\n");
216+
wait();
207217
}
208218

209219

@@ -213,43 +223,50 @@ mod tests {
213223
// GET /api/address/:address
214224
let binding = format!("address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv").clone();
215225
let prices: &str = blocking(&binding).expect("REASON");
226+
wait();
216227
}
217228
#[test]
218229
fn test_address_txs(){
219230
// GET /api/address/:address/txs
220231
let binding = format!("address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs").clone();
221232
let prices: &str = blocking(&binding).expect("REASON");
233+
wait();
222234
}
223235
#[test]
224236
fn test_address_txs_chain(){
225237
// GET /api/address/:address/txs/chain
226238
let binding = format!("address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs/chain").clone();
227239
let prices: &str = blocking(&binding).expect("REASON");
240+
wait();
228241
}
229242
#[test]
230243
fn test_address_txs_mempool(){
231244
// GET /api/address/:address/txs/mempool
232245
let binding = format!("address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs/mempool").clone();
233246
let prices: &str = blocking(&binding).expect("REASON");
247+
wait();
234248
}
235249
#[test]
236250
fn test_address_txs_utxo(){
237251
// GET /api/address/:address/utxo
238252
let binding = format!("address/1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY/utxo").clone();
239253
let prices: &str = blocking(&binding).expect("REASON");
254+
wait();
240255
}
241256
#[test]
242257
fn test_validate_address(){
243258
// GET /api/v1/validate-address/:address
244259
let binding = format!("v1/validate-address/1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY").clone();
245260
let prices: &str = blocking(&binding).expect("REASON");
261+
wait();
246262
}
247263

248264
/// Blocks
249265
#[test]
250266
fn test_blockheight() {
251267
let blockheight = blockheight::blockheight();
252268
assert_ne!(0 as f64, blockheight.unwrap());
269+
wait();
253270
}
254271
/// Mining
255272
/// Fees
@@ -263,13 +280,15 @@ mod tests {
263280
#[test]
264281
fn test_add() {
265282
// assert_eq!(add(1, 2), 3);
283+
wait();
266284
}
267285

268286
#[test]
269287
fn test_bad_add() {
270288
// This assert would fire and test will fail.
271289
// Please note, that private functions can be tested too!
272290
// assert_ne!(bad_add(1, 2), 3);
291+
wait();
273292
}
274293

275294
use std::panic::{catch_unwind, AssertUnwindSafe};
@@ -280,5 +299,6 @@ mod tests {
280299
}));
281300

282301
assert_ne!("foo panic message", *msg.unwrap_err().downcast_ref::<&str>().unwrap());
302+
wait();
283303
}
284304
}

0 commit comments

Comments
 (0)