Skip to content

Commit

Permalink
Merge pull request #1443 from NASA-AMMOS/fix/write-parents-unfinished…
Browse files Browse the repository at this point in the history
…-spans

Write parents of unfinished spans
  • Loading branch information
Mythicaeda authored May 13, 2024
2 parents 2b61386 + f2d8bd5 commit 1ebfad6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import javax.json.Json;
import javax.json.JsonValue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -90,6 +92,51 @@ void simulationMicrosecondResolution() throws IOException {
assertDoesNotThrow(() -> hasura.awaitSimulation(planId));
}

/**
* ParentIds of child spans should be posted regardless of if the span is finished.
*/
@Test
void incompleteParentIdsPosted() throws IOException {
hasura.insertActivity(planId, "parent", "0h", JsonValue.EMPTY_JSON_OBJECT);
hasura.insertActivity(planId, "DecomposingSpawnParent", "0h", JsonValue.EMPTY_JSON_OBJECT);
final var simulatedActivities = hasura.getSimulationDataset(hasura.awaitSimulation(planId).simDatasetId())
.activities();

assertEquals(6, simulatedActivities.size());

final var typeMap = new HashMap<String, ArrayList<SimulatedActivity>>();
simulatedActivities.forEach(act -> typeMap.computeIfAbsent(act.type(), k -> new ArrayList<>()).add(act));

// Check parentIds are present on unfinished activities
assertEquals(1, typeMap.get("parent").size());
final var parent = typeMap.get("parent").get(0);
assertNull(parent.parentId());
assertNull(parent.duration());

assertEquals(1, typeMap.get("child").size());
final var child = typeMap.get("child").get(0);
assertEquals(parent.spanId(), child.parentId());
assertNull(child.duration());

assertEquals(1, typeMap.get("grandchild").size());
final var grandchild = typeMap.get("grandchild").get(0);
assertEquals(child.spanId(), grandchild.parentId());
assertNull(grandchild.duration());

// Check parentIds are present on finished activities
assertEquals(1, typeMap.get("DecomposingSpawnParent").size());
final var decompParent = typeMap.get("DecomposingSpawnParent").get(0);
assertNull(decompParent.parentId());
assertNotNull(decompParent.duration());

assertEquals(2, typeMap.get("DecomposingSpawnChild").size());
typeMap.get("DecomposingSpawnChild")
.forEach(dsc -> {
assertEquals(decompParent.spanId(), dsc.parentId());
assertNotNull(dsc.duration());
});
}

@Nested
class TemporalSubsetSimulation {
private int firstHalfActivityId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ private static void postActivities(

updateSimulatedActivityParentsAction.apply(
datasetId,
simulatedActivityRecords,
allActivityRecords,
simIdToPgId);
}
}
Expand Down

0 comments on commit 1ebfad6

Please sign in to comment.