fix(events): coalesce in-flight feature intent replay
Release / release (push) Failing after 19m41s

This commit is contained in:
dmg committed 2026-09-27 10:53:50 -04:00
1 parent 9bb56f3a1c
commit e04a3152c1
4 files changed
+122 -9

No files matched your search

@@ -398,7 +398,9 @@ class AdventureQuestNativeTest {
}
var earned=exportedCampEvents(data).stream().filter(event->event.get("type").getAsString()
.endsWith("adventure.trophy_earned")).toList();
assertEquals(1,earned.size());
assertEquals(1,earned.size(),()->"Exported camp earned count="+earned.size()+" records="
+earned.stream().map(event->"id="+event.get("id").getAsString()+",receipt="
+event.getAsJsonObject("data").get("receipt_id").getAsString()).toList());
var details=earned.getFirst().getAsJsonObject("data");
assertEquals(receiptId.toString(),details.get("receipt_id").getAsString());
assertEquals(finalEnemy.toString(),details.get("final_enemy_id").getAsString());
@@ -782,13 +784,21 @@ class AdventureQuestNativeTest {
private static void awaitCampExport(FantasyStickLifecycleNativeTest.Fixture fixture,Path root,
UUID receipt)throws Exception{
var eventId=UUID.nameUUIDFromBytes(("fantasystick:fishing:"+receipt
+":adventure.trophy_earned").getBytes(java.nio.charset.StandardCharsets.UTF_8));
var ownerIntent=root.resolve("fishing-event-intents").resolve(eventId+".pending");
var logIntent=root.resolve("events/pending").resolve(eventId+".pending");
for(int attempt=0;attempt<200;attempt++){
if(hasExportedCampReceipt(root,receipt))return;
if(hasExportedCampReceipt(root,receipt)&&java.nio.file.Files.notExists(ownerIntent)
&&java.nio.file.Files.notExists(logIntent))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");
assertTrue(hasExportedCampReceipt(root,receipt)
&&java.nio.file.Files.notExists(ownerIntent)&&java.nio.file.Files.notExists(logIntent),
"Committed camp receipt "+receipt+" did not complete exported JSONL/intent handoff before shutdown"
+"; owner_pending="+java.nio.file.Files.exists(ownerIntent)
+"; log_pending="+java.nio.file.Files.exists(logIntent));
}
private static boolean hasExportedCampReceipt(Path root,UUID receipt){
try{return exportedCampEvents(root).stream().anyMatch(event->event.get("type").getAsString()
@@ -23,6 +23,52 @@ class FishingEventBridgePartsNativeTest {
@org.junit.jupiter.api.BeforeAll static void bootstrap() throws Exception { NativeRuntime.bootstrap(); }
@TempDir Path data;
@Test void campStartupReplayDoesNotRepublishAnAlreadyExportedUnacknowledgedIntent() throws Exception {
var character=UUID.randomUUID();var receiptId=UUID.randomUUID();
var receipt=new games.dmg.fantasystick.adventure.FishingState.Trophy(receiptId,
games.dmg.fantasystick.adventure.FishingState.TrophyType.CAMP,character,
UUID.randomUUID(),UUID.randomUUID(),UUID.randomUUID(),UUID.randomUUID(),
"Spoils of Restart Camp","Restart Camp",Map.of(character,
new games.dmg.fantasystick.adventure.FishingState.Reward(
java.math.BigInteger.ONE,java.math.BigInteger.ZERO)),
games.dmg.fantasystick.adventure.FishingState.TrophyPhase.EARNED,
Map.of("final_enemy_id",UUID.randomUUID().toString(),"unit_kind","solo",
"unit_id",character.toString(),"accepted_roster",character.toString(),
"arena_shape","circle","arena_x_blocks","10","arena_z_blocks","10"));
var log=LocalEventLog.open(data,Clock.systemUTC(),
new LocalEventLog.RuntimeInfo("test","test","test"),128,1_000_000,ignored->{});
log.ready().toCompletableFuture().get(5,TimeUnit.SECONDS);
var allowFirstAcknowledgement=new CompletableFuture<Void>();
var firstExported=new CompletableFuture<Void>();
var deliveries=new java.util.concurrent.atomic.AtomicInteger();
var bridge=new FishingEventBridge(event->{
var result=log.emit(event);
if(deliveries.incrementAndGet()==1)return result.thenCompose(status->{
firstExported.complete(null);
return allowFirstAcknowledgement.thenApply(ignored->status);
});
return result;
},Clock.systemUTC(),data,mock(EquipmentSessions.class),ignored->{});
bridge.trophyEarned(receipt);
firstExported.get(5,TimeUnit.SECONDS);
bridge.replay();
bridge.close();bridge.drained().toCompletableFuture().get(5,TimeUnit.SECONDS);
allowFirstAcknowledgement.complete(null);
log.close();
var earned=new ArrayList<com.google.gson.JsonObject>();
try(var files=java.nio.file.Files.walk(data.resolve("events"))){
for(var path:files.filter(value->value.toString().endsWith(".jsonl")).toList())
for(var line:java.nio.file.Files.readAllLines(path)){
var event=com.google.gson.JsonParser.parseString(line).getAsJsonObject();
if(event.get("type").getAsString().endsWith("adventure.trophy_earned"))earned.add(event);
}
}
assertEquals(1,earned.size(),()->"camp receipt="+receiptId+" exported IDs="
+earned.stream().map(event->event.get("id").getAsString()).toList());
assertEquals(receiptId.toString(),earned.getFirst().getAsJsonObject("data")
.get("receipt_id").getAsString());
}
@Test void rejectedChampionIntentReplaysFromFrozenReceiptIntoExportedJsonl() throws Exception {
var carrier=UUID.randomUUID();var zero=UUID.randomUUID();var receiptId=UUID.randomUUID();
var receipt=new games.dmg.fantasystick.adventure.FishingState.Trophy(receiptId,