Commit 2a0d8652 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Streamline testing using channels in favour of condvars and factor out test server start

parent fb89cdc1
......@@ -219,31 +219,37 @@ fn main() {
#[cfg(test)]
mod tests {
use super::*;
use std::io::Read;
#[test]
fn start_server_and_check_request() {
fn start_server_and_fn<F>(f: F) where F: FnOnce() {
use std::{thread, time};
use std::sync::mpsc::channel;
let (start_tx, start_rx) = channel();
let (stop_tx, stop_rx) = channel();
thread::spawn(move || {
let mut conn = Connection::open_in_memory().unwrap();
db_apply_migrations::test(&mut conn);
let mut config = read_config_from_file(Path::new("thisfileshoudnotexist"));
let srvr = start_server(conn, config);
// add contests / tasks here
use std::sync::{Arc, Mutex, Condvar};
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair_ = pair.clone();
start_tx.send(()).unwrap();
let mut config = read_config_from_file(Path::new("thisfileshoudnotexist"));
stop_rx.recv().unwrap();
let srvr = start_server(conn, config);
srvr.unwrap().close().unwrap();
});
thread::spawn(move || {
// wait for server to start:
start_rx.recv().unwrap();
thread::sleep(time::Duration::from_millis(100));
f();
stop_tx.send(()).unwrap();
}
use std::io::Read;
#[test]
fn start_server_and_check_request() {
start_server_and_fn(||{
let mut resp = reqwest::get("http://localhost:8080").unwrap();
assert!(resp.status().is_success());
......@@ -251,23 +257,6 @@ mod tests {
resp.read_to_string(&mut content);
assert!(content.contains("<h1>Jugendwettbewerb Informatik</h1>"));
assert!(!content.contains("Error"));
let &(ref lock, ref cvar) = &*pair_;
let mut should_exit = lock.lock().unwrap();
*should_exit = true;
cvar.notify_one();
//fs::copy("foo.txt", "bar.txt").unwrap();
});
// Copied from docs
let &(ref lock, ref cvar) = &*pair;
let mut should_exit = lock.lock().unwrap();
while !*should_exit {
should_exit = cvar.wait(should_exit).unwrap();
}
srvr.unwrap().close().unwrap();
assert!(true);
})
}
}
......@@ -230,21 +230,6 @@ impl<'c, 'a: 'c, 'b: 'c + 'a, T> RequestAugmentMedalError<'c, 'a, 'b, T> for Res
}
<<<<<<< HEAD
fn greet(_req: &mut Request) -> IronResult<Response> {
// hier ggf. Daten aus dem Request holen
// Daten verarbeiten
let (template, data) = functions::blaa();
// Antwort erstellen und zurücksenden
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
Ok(resp)
}
=======
>>>>>>> remove some unused functions, unused muts, unused vars
fn greet_personal(req: &mut Request) -> IronResult<Response> {
let session_token = req.get_session_token();
// hier ggf. Daten aus dem Request holen
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment