Group core integration tests by behavior (#102)
This commit is contained in:
1 parent
4548b6ac64
commit
c716c2c759
32 files changed
+4508
-4414
No files matched your search
@@ -0,0 +1,290 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn only_a_live_insert_reports_what_the_match_brought_to_the_challenge() {
|
||||
use arena_tracker_core::MatchEnd::*;
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
let follow = || reported_round(&tracker);
|
||||
assert!(follow().is_empty(), "history import");
|
||||
for (i, (placement, expected)) in [
|
||||
(6, Mark),
|
||||
(2, Mark),
|
||||
(3, Nothing),
|
||||
(1, Completed),
|
||||
(1, Nothing),
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let id = common::recorded_game_id() + i as u64;
|
||||
world.client.set_game_id(Some(id));
|
||||
world.client.set_phase("InProgress", true);
|
||||
assert!(follow().is_empty());
|
||||
world.history.add_unlisted(payload(
|
||||
&format!("EUW1_{id}"),
|
||||
1750,
|
||||
222,
|
||||
"Jinx",
|
||||
placement,
|
||||
placement <= 3,
|
||||
at(date(2026, 4, 5), i as i64),
|
||||
));
|
||||
world.client.set_phase("EndOfGame", true);
|
||||
let events = follow();
|
||||
assert_eq!(events.len(), 1);
|
||||
assert_eq!((events[0].champion_id, events[0].end), (222, expected));
|
||||
assert_eq!(events[0].puuid, SELF_PUUID);
|
||||
assert_eq!(events[0].season, S2);
|
||||
assert!(follow().is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_game_the_client_gave_no_id_for_is_reported_when_a_sync_stores_it() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
assert!(reported_round(&tracker).is_empty(), "history import");
|
||||
world.client.set_game_id(None);
|
||||
world.client.set_phase("InProgress", true);
|
||||
assert!(reported_round(&tracker).is_empty());
|
||||
world.history.add(payload(
|
||||
"EUW1_900",
|
||||
1750,
|
||||
222,
|
||||
"Jinx",
|
||||
6,
|
||||
false,
|
||||
now() + 60_000,
|
||||
));
|
||||
world.client.set_phase("EndOfGame", true);
|
||||
|
||||
let events = reported_round(&tracker);
|
||||
|
||||
assert_eq!(
|
||||
events
|
||||
.iter()
|
||||
.map(|e| (e.champion_id, e.end))
|
||||
.collect::<Vec<_>>(),
|
||||
[(222, MatchEnd::Mark)]
|
||||
);
|
||||
assert!(reported_round(&tracker).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_older_match_a_sync_brings_is_history_and_the_game_without_an_id_still_waits() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
assert!(reported_round(&tracker).is_empty(), "history import");
|
||||
world.client.set_game_id(None);
|
||||
world.client.set_phase("InProgress", true);
|
||||
assert!(reported_round(&tracker).is_empty());
|
||||
// A game played before this one, newer than every Match stored, that Riot lists only now.
|
||||
world.history.add(payload(
|
||||
"EUW1_earlier",
|
||||
1750,
|
||||
11,
|
||||
"Ahri",
|
||||
2,
|
||||
true,
|
||||
now() - 30 * 60_000,
|
||||
));
|
||||
world.client.set_phase("EndOfGame", true);
|
||||
|
||||
assert!(reported_round(&tracker).is_empty());
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 3);
|
||||
|
||||
// The followed game's Match, published later, is the one reported.
|
||||
world.history.add(new_match("EUW1_followed", 1));
|
||||
let events = reported_round(&tracker);
|
||||
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 4);
|
||||
assert_eq!(
|
||||
events
|
||||
.iter()
|
||||
.map(|e| (e.champion_id, e.end))
|
||||
.collect::<Vec<_>>(),
|
||||
[(222, MatchEnd::Completed)]
|
||||
);
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
let calls = world.source_calls();
|
||||
assert!(reported_round(&tracker).is_empty());
|
||||
assert_eq!(world.source_calls(), calls, "the wait is over");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_platform_the_first_import_reports_only_the_game_the_client_named() {
|
||||
let world = World::new(&[]);
|
||||
let tracker = world.tracker();
|
||||
assert!(reported_round(&tracker).is_empty());
|
||||
world.client.set_game_id(Some(common::recorded_game_id()));
|
||||
world.client.set_phase("InProgress", true);
|
||||
assert!(reported_round(&tracker).is_empty());
|
||||
world.history.add(payload(
|
||||
"EUW1_1",
|
||||
1750,
|
||||
11,
|
||||
"Ahri",
|
||||
3,
|
||||
true,
|
||||
at(date(2026, 4, 4), 1),
|
||||
));
|
||||
world.history.add(finished_match(1750));
|
||||
world.client.set_phase("EndOfGame", true);
|
||||
|
||||
let events = reported_round(&tracker);
|
||||
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
assert_eq!(
|
||||
events
|
||||
.iter()
|
||||
.map(|e| (e.champion_id, e.end))
|
||||
.collect::<Vec<_>>(),
|
||||
[(222, MatchEnd::Completed)]
|
||||
);
|
||||
assert!(reported_round(&tracker).is_empty(), "already stored");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_finished_game_is_fetched_by_its_id_even_in_a_queue_nobody_lists() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
play_arena_game(&world, &tracker);
|
||||
world.history.add_unlisted(finished_match(1800));
|
||||
let (calls, listed) = (world.source_calls(), world.history.listed_counter());
|
||||
let listed_before = listed.load(Ordering::SeqCst);
|
||||
|
||||
assert!(round(&tracker));
|
||||
|
||||
assert_eq!(world.source_calls(), calls + 1, "one request, no listing");
|
||||
assert_eq!(listed.load(Ordering::SeqCst), listed_before);
|
||||
let matches = tracker.matches(SELF_PUUID).unwrap();
|
||||
assert_eq!(matches.len(), 3);
|
||||
assert_eq!(matches.last().unwrap().format, Format::Other(1800));
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
world.client.set_phase("None", false);
|
||||
assert!(!round(&tracker));
|
||||
assert_eq!(
|
||||
world.source_calls(),
|
||||
calls + 1,
|
||||
"a stored Match ends the wait"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_match_riot_publishes_late_is_stored_once_it_appears() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
play_arena_game(&world, &tracker);
|
||||
|
||||
for _ in 0..5 {
|
||||
let calls = world.source_calls();
|
||||
round(&tracker);
|
||||
assert_eq!(world.source_calls(), calls + 1, "one request per round");
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
}
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
|
||||
world.history.add_unlisted(finished_match(1750));
|
||||
assert!(round(&tracker));
|
||||
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 3);
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_match_that_never_appears_is_pending_and_an_empty_refresh_keeps_it_so() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
play_arena_game(&world, &tracker);
|
||||
let calls = world.source_calls();
|
||||
|
||||
for _ in 0..MATCH_RETRIES {
|
||||
round(&tracker);
|
||||
}
|
||||
|
||||
assert_eq!(world.source_calls(), calls + MATCH_RETRIES);
|
||||
assert_eq!(tracker.status().problem, Some(UpdateProblem::MatchPending));
|
||||
assert!(!round(&tracker));
|
||||
assert_eq!(
|
||||
world.source_calls(),
|
||||
calls + MATCH_RETRIES,
|
||||
"the wait is over"
|
||||
);
|
||||
|
||||
let report = tracker.refresh(&mut |_| {}).unwrap();
|
||||
assert_eq!(report.added, 0);
|
||||
assert_eq!(tracker.status().problem, Some(UpdateProblem::MatchPending));
|
||||
|
||||
world.history.add(finished_match(1750));
|
||||
assert_eq!(tracker.refresh(&mut |_| {}).unwrap().added, 1);
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_match_fetched_by_its_id_is_never_stored_twice() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
play_arena_game(&world, &tracker);
|
||||
world.history.add(finished_match(1750));
|
||||
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 3);
|
||||
let report = tracker.refresh(&mut |_| {}).unwrap();
|
||||
|
||||
assert_eq!((report.added, report.stored), (0, 3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_finished_game_that_is_not_an_arena_match_ends_the_wait_without_storing_it() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
play_arena_game(&world, &tracker);
|
||||
world.history.add_unlisted(finished_match(1704));
|
||||
|
||||
round(&tracker);
|
||||
let calls = world.source_calls();
|
||||
round(&tracker);
|
||||
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
assert_eq!(world.source_calls(), calls, "nothing left to wait for");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_fetch_by_id_is_recorded_and_tried_again() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
play_arena_game(&world, &tracker);
|
||||
world.history.add_unlisted(finished_match(1750));
|
||||
world
|
||||
.history
|
||||
.fail_with(Some(SourceError::Network("coupé".into())));
|
||||
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().problem, Some(UpdateProblem::Network));
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
|
||||
world.history.fail_with(None);
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 3);
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_stored_match_to_give_the_platform_a_normal_sync_looks_for_the_game() {
|
||||
let world = World::new(&[]);
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
play_arena_game(&world, &tracker);
|
||||
world.history.add(finished_match(1750));
|
||||
|
||||
round(&tracker);
|
||||
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 1);
|
||||
}
|
||||
Reference in new issue
Block a user