use super::*; #[test] fn the_match_of_an_arena_game_that_just_ended_is_stored() { let world = World::new(&s2_matches()); let tracker = world.tracker(); round(&tracker); let calls = world.source_calls(); world.client.set_phase("ChampSelect", false); round(&tracker); world.client.set_phase("InProgress", true); assert!(!round(&tracker)); assert_eq!( world.source_calls(), calls, "nothing to fetch while the game runs" ); world.history.add(new_match("EUW1_just_played", 1)); world.client.set_phase("EndOfGame", true); assert!(round(&tracker)); assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 3); assert_eq!(tracker.status().problem, None); let calls = world.source_calls(); world.client.set_phase("None", false); assert!(!round(&tracker)); assert_eq!(world.source_calls(), calls, "a stored Match ends the wait"); let report = tracker.refresh(&mut |_| {}).unwrap(); assert_eq!((report.added, report.stored), (0, 3)); } #[test] fn a_match_that_shows_up_late_is_still_stored_without_leaving_a_problem() { let world = World::new(&s2_matches()); let tracker = world.tracker(); round(&tracker); world.client.set_phase("Reconnect", true); round(&tracker); world.client.set_phase("WaitingForStats", true); round(&tracker); round(&tracker); assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2); world.history.add(new_match("EUW1_late", 1)); round(&tracker); tracker.wait_for_client(); assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 3); assert_eq!(tracker.status().problem, None); assert_eq!(world.client.waits(), [Duration::from_secs(60)]); } #[test] fn while_a_match_is_pending_client_events_still_end_the_wait() { let world = World::new(&s2_matches()); let tracker = world.tracker(); round(&tracker); world.client.set_phase("InProgress", true); round(&tracker); world.client.set_phase("EndOfGame", true); round(&tracker); let started = Instant::now(); tracker.wait_for_client(); assert!(started.elapsed() < Duration::from_secs(1), "no sleep"); assert_eq!(world.client.waits(), [Duration::from_secs(20)]); } #[test] fn a_burst_of_client_events_makes_one_request_per_retry_interval() { let world = World::new(&s2_matches()); let tracker = world.tracker(); round(&tracker); play_arena_game(&world, &tracker); let calls = world.source_calls(); round(&tracker); for _ in 0..5 { round_after(&tracker, 0); } assert_eq!(world.source_calls(), calls + 1); round_after(&tracker, RETRY_EVERY_MS - 1); assert_eq!(world.source_calls(), calls + 1); round_after(&tracker, 1); assert_eq!(world.source_calls(), calls + 2); } #[test] fn the_matches_of_two_games_ended_in_a_row_are_both_stored() { let world = World::new(&s2_matches()); let tracker = world.tracker(); let game_b = two_games_in_a_row(&world, &tracker); world.history.add_unlisted(match_of_game(game_b)); round(&tracker); assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 3); world.history.add_unlisted(finished_match(1750)); round(&tracker); assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 4); assert_eq!(tracker.status().problem, None); let calls = world.source_calls(); round(&tracker); assert_eq!(world.source_calls(), calls, "nothing left to wait for"); } #[test] fn the_first_of_two_games_is_pending_after_its_own_tries_once_the_second_is_stored() { let world = World::new(&s2_matches()); let tracker = world.tracker(); let game_b = two_games_in_a_row(&world, &tracker); world.history.add_unlisted(match_of_game(game_b)); // Game A was tried twice already. for _ in 2..MATCH_RETRIES - 1 { round(&tracker); assert_eq!(tracker.status().problem, None); } assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 3); round(&tracker); assert_eq!(tracker.status().problem, Some(UpdateProblem::MatchPending)); } #[test] fn a_match_that_never_shows_up_is_reported_pending_until_a_refresh_finds_it() { let world = World::new(&s2_matches()); let tracker = world.tracker(); round(&tracker); world.client.set_phase("InProgress", true); round(&tracker); world.client.set_phase("EndOfGame", true); for _ in 1..MATCH_RETRIES { round(&tracker); assert_eq!(tracker.status().problem, None); } assert!(round(&tracker)); assert_eq!(tracker.status().problem, Some(UpdateProblem::MatchPending)); tracker.wait_for_client(); assert_eq!(world.client.waits(), [Duration::from_secs(60)]); let calls = world.source_calls(); assert!(!round(&tracker)); assert_eq!(world.source_calls(), calls, "the round gave up"); world.history.add(new_match("EUW1_finally", 1)); let report = tracker.refresh(&mut |_| {}).unwrap(); assert_eq!(report.added, 1); assert_eq!(tracker.status().problem, None); } #[test] fn a_game_that_is_not_arena_triggers_nothing() { let world = World::new(&s2_matches()); let tracker = world.tracker(); round(&tracker); let calls = world.source_calls(); world.client.set_phase("InProgress", false); round(&tracker); world.client.set_phase("EndOfGame", false); assert!(!round(&tracker)); assert_eq!(world.source_calls(), calls); assert_eq!(tracker.status().problem, None); tracker.wait_for_client(); assert_eq!(world.client.waits(), [Duration::from_secs(60)]); }