diff --git a/src/nativeTest/java/games/dmg/fantasystick/AdventureQuestNativeTest.java b/src/nativeTest/java/games/dmg/fantasystick/AdventureQuestNativeTest.java index 4bddf1b..5c88e35 100644 --- a/src/nativeTest/java/games/dmg/fantasystick/AdventureQuestNativeTest.java +++ b/src/nativeTest/java/games/dmg/fantasystick/AdventureQuestNativeTest.java @@ -393,6 +393,7 @@ class AdventureQuestNativeTest { await(restarted,()->!fishing.trophies(carrier).isEmpty()); assertEquals(finalEnemy.toString(),fishing.trophies(carrier).getFirst().audit() .get("final_enemy_id")); + awaitCampExport(restarted,data,receiptId); restarted.plugin.setEnabled(false); } var earned=exportedCampEvents(data).stream().filter(event->event.get("type").getAsString() @@ -779,6 +780,22 @@ class AdventureQuestNativeTest { } } + private static void awaitCampExport(FantasyStickLifecycleNativeTest.Fixture fixture,Path root, + UUID receipt)throws Exception{ + for(int attempt=0;attempt<200;attempt++){ + if(hasExportedCampReceipt(root,receipt))return; + var task=fixture.tasks.poll(25,java.util.concurrent.TimeUnit.MILLISECONDS); + if(task!=null)task.run(); + } + assertTrue(hasExportedCampReceipt(root,receipt), + "Committed camp receipt "+receipt+" did not reach exported JSONL before shutdown"); + } + private static boolean hasExportedCampReceipt(Path root,UUID receipt){ + try{return exportedCampEvents(root).stream().anyMatch(event->event.get("type").getAsString() + .endsWith("adventure.trophy_earned")&&event.getAsJsonObject("data") + .get("receipt_id").getAsString().equals(receipt.toString()));} + catch(Exception transientExport){return false;} + } private static List exportedCampEvents(Path root)throws Exception{ try(var files=java.nio.file.Files.walk(root.resolve("events"))){ return files.filter(path->path.toString().endsWith(".jsonl"))