Skip to content

Commit

Permalink
Add E2E Tests
Browse files Browse the repository at this point in the history
- Update queries used in tests
- Collapse "insert goal" and "add goal to scheduling spec" into a single function
  • Loading branch information
Mythicaeda committed Feb 1, 2024
1 parent 4e71d94 commit b2c680e
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 112 deletions.
179 changes: 128 additions & 51 deletions e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/SchedulingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import gov.nasa.jpl.aerie.e2e.utils.HasuraRequests;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.opentest4j.AssertionFailedError;

import javax.json.Json;
import javax.json.JsonObject;
Expand Down Expand Up @@ -143,11 +145,11 @@ private void insertActivities() throws IOException {
@Test
void twoInARow() throws IOException {
// Setup: Add Goal
final int bakeBananaBreadGoalId = hasura.insertSchedulingGoal(
final int bakeBananaBreadGoalId = hasura.createSchedulingSpecGoal(
"BakeBanana Scheduling Test Goal",
modelId,
bakeBananaGoalDefinition);
hasura.createSchedulingSpecGoal(bakeBananaBreadGoalId, schedulingSpecId, 0);
bakeBananaGoalDefinition,
schedulingSpecId,
0);
try {
// Schedule and get Plan
hasura.awaitScheduling(schedulingSpecId);
Expand All @@ -174,14 +176,14 @@ void getSchedulingDSLTypeScript() throws IOException {
@Test
void schedulingRecurrenceGoal() throws IOException {
// Setup: Add Goal
final int recurrenceGoalId = hasura.insertSchedulingGoal(
final int recurrenceGoalId = hasura.createSchedulingSpecGoal(
"Recurrence Scheduling Test Goal",
modelId,
recurrenceGoalDefinition);
hasura.createSchedulingSpecGoal(recurrenceGoalId, schedulingSpecId, 0);
recurrenceGoalDefinition,
schedulingSpecId,
0);
try {
// Schedule and get Plan
hasura.awaitScheduling(schedulingSpecId);
hasura.awaitScheduling(schedulingSpecId, 100000000);
final var plan = hasura.getPlan(planId);
final var activities = plan.activityDirectives();

Expand All @@ -198,11 +200,11 @@ void schedulingRecurrenceGoal() throws IOException {
void schedulingCoexistenceGoal() throws IOException {
// Setup: Add Goal and Activities
insertActivities();
final int coexistenceGoalId = hasura.insertSchedulingGoal(
final int coexistenceGoalId = hasura.createSchedulingSpecGoal(
"Coexistence Scheduling Test Goal",
modelId,
coexistenceGoalDefinition);
hasura.createSchedulingSpecGoal(coexistenceGoalId, schedulingSpecId, 0);
coexistenceGoalDefinition,
schedulingSpecId,
0);

try {
// Schedule and get Plan
Expand Down Expand Up @@ -235,16 +237,16 @@ void schedulingCoexistenceGoal() throws IOException {
void schedulingMultipleGoals() throws IOException {
// Setup: Add Goals
insertActivities();
final int recurrenceGoalId = hasura.insertSchedulingGoal(
final int recurrenceGoalId = hasura.createSchedulingSpecGoal(
"Recurrence Scheduling Test Goal",
modelId,
recurrenceGoalDefinition);
hasura.createSchedulingSpecGoal(recurrenceGoalId, schedulingSpecId, 0);
final int coexistenceGoalId = hasura.insertSchedulingGoal(
recurrenceGoalDefinition,
schedulingSpecId,
0);
final int coexistenceGoalId = hasura.createSchedulingSpecGoal(
"Coexistence Scheduling Test Goal",
modelId,
coexistenceGoalDefinition);
hasura.createSchedulingSpecGoal(coexistenceGoalId, schedulingSpecId, 1);
coexistenceGoalDefinition,
schedulingSpecId,
1);
try {
// Schedule and get Plan
hasura.awaitScheduling(schedulingSpecId);
Expand Down Expand Up @@ -360,11 +362,11 @@ void outdatedPlanRevision() throws IOException {
hasura.insertActivity(planId, "GrowBanana", "5h", JsonObject.EMPTY_JSON_OBJECT);

// Setup: Add Goal
final int coexistenceGoalId = hasura.insertSchedulingGoal(
final int coexistenceGoalId = hasura.createSchedulingSpecGoal(
"Coexistence Scheduling Test Goal",
modelId,
coexistenceGoalDefinition);
hasura.createSchedulingSpecGoal(coexistenceGoalId, schedulingSpecId, 0);
coexistenceGoalDefinition,
schedulingSpecId,
0);

try {
hasura.updatePlanRevisionSchedulingSpec(planId);
Expand Down Expand Up @@ -411,11 +413,11 @@ void outdatedSimConfig() throws IOException {
hasura.awaitSimulation(planId);
hasura.deleteSimTemplate(templateId); // Return to blank sim config args

final int plantGoal = hasura.insertSchedulingGoal(
final int plantGoal = hasura.createSchedulingSpecGoal(
"Scheduling Test: When Plant < 300",
modelId,
plantCountGoalDefinition);
hasura.createSchedulingSpecGoal(plantGoal, schedulingSpecId, 0);
plantCountGoalDefinition,
schedulingSpecId,
0);

try {
hasura.awaitScheduling(schedulingSpecId);
Expand Down Expand Up @@ -458,11 +460,11 @@ void injectedResultsLoaded() throws IOException{
List.of(new ProfileSegment("0h", false, Json.createValue(400))));

// Insert Goal
final int plantGoal = hasura.insertSchedulingGoal(
final int plantGoal = hasura.createSchedulingSpecGoal(
"Scheduling Test: When Plant < 300",
modelId,
plantCountGoalDefinition);
hasura.createSchedulingSpecGoal(plantGoal, schedulingSpecId, 0);
plantCountGoalDefinition,
schedulingSpecId,
0);

try {
hasura.awaitScheduling(schedulingSpecId);
Expand All @@ -486,11 +488,11 @@ void temporalSubsetExcluded() throws IOException {
hasura.awaitSimulation(planId);

// Setup: Add Goal
final int coexistenceGoalId = hasura.insertSchedulingGoal(
final int coexistenceGoalId = hasura.createSchedulingSpecGoal(
"Coexistence Scheduling Test Goal",
modelId,
coexistenceGoalDefinition);
hasura.createSchedulingSpecGoal(coexistenceGoalId, schedulingSpecId, 0);
coexistenceGoalDefinition,
schedulingSpecId,
0);

try {
// Schedule and get Plan
Expand Down Expand Up @@ -544,16 +546,16 @@ void beforeEach() throws IOException {
false);

// Add Goal
cardinalityGoalId = hasura.insertSchedulingGoal(
cardinalityGoalId = hasura.createSchedulingSpecGoal(
"Cardinality and Decomposition Scheduling Test Goal",
modelId,
"""
export default function cardinalityGoalExample() {
return Goal.CardinalityGoal({
activityTemplate: ActivityTemplates.parent({ label: "unlabeled"}),
specification: { duration: Temporal.Duration.from({ seconds: 10 }) },
});}""");
hasura.createSchedulingSpecGoal(cardinalityGoalId, schedulingSpecId, 0);
});}""",
schedulingSpecId,
0);
}

@AfterEach
Expand Down Expand Up @@ -632,19 +634,18 @@ void beforeEach() throws IOException {
List.of(myBooleanProfile));

// Insert Goal
edGoalId = hasura.insertSchedulingGoal(
edGoalId = hasura.createSchedulingSpecGoal(
"On my_boolean true",
modelId,
"""
export default function myGoal() {
return Goal.CoexistenceGoal({
forEach: Discrete.Resource("/my_boolean").equal(true).assignGaps(false),
activityTemplate: ActivityTemplates.BiteBanana({ biteSize: 1, }),
startsAt:TimingConstraint.singleton(WindowProperty.END)
})
}""");
// Add the goal
hasura.createSchedulingSpecGoal(edGoalId, schedulingSpecId, 0);
}""",
schedulingSpecId,
0);
}

@AfterEach
Expand Down Expand Up @@ -730,7 +731,7 @@ void beforeEach() throws IOException, InterruptedException {
gateway.uploadFooJar(),
"Foo (e2e tests)",
"aerie_e2e_tests",
"Simulation Tests");
"Scheduling Tests");
}
// Insert the Plan
fooPlan = hasura.createPlan(
Expand All @@ -749,17 +750,17 @@ void beforeEach() throws IOException, InterruptedException {
false);

// Add Goal
fooGoalId = hasura.insertSchedulingGoal(
fooGoalId = hasura.createSchedulingSpecGoal(
"Foo Recurrence Test Goal",
fooId,
"""
export default function recurrenceGoalExample() {
return Goal.ActivityRecurrenceGoal({
activityTemplate: ActivityTemplates.bar(),
interval: Temporal.Duration.from({ hours: 2 }),
});
}""");
hasura.createSchedulingSpecGoal(fooGoalId, fooSchedulingSpecId, 0);
}""",
fooSchedulingSpecId,
0);
}

@AfterEach
Expand Down Expand Up @@ -795,4 +796,80 @@ void cancelingSchedulingUpdatesRequestReason() throws IOException {
assertEquals("Scheduling was interrupted while "+ reasonData.getString("location"), reasonData.getString("message"));
}
}

@Nested
class VersioningSchedulingGoals {
@Test
void goalVersionLocking() throws IOException {
final int goalId = hasura.createSchedulingSpecGoal(
"coexistence goal",
coexistenceGoalDefinition,
schedulingSpecId,
0);

try {
// Update the plan's constraint specification to use a specific version
hasura.updateSchedulingSpecVersion(schedulingSpecId, goalId, 0);

// Update definition to have invalid syntax
final int newRevision = hasura.updateGoalDefinition(
goalId,
"error :-(");

// Schedule -- should succeed
final var initResults = hasura.awaitScheduling(schedulingSpecId);
assertEquals("complete", initResults.status());

// Update scheduling spec to use invalid definition
hasura.updateSchedulingSpecVersion(schedulingSpecId, goalId, newRevision);

// Schedule -- should fail
final var error = Assertions.assertThrows(
AssertionFailedError.class,
() -> hasura.awaitScheduling(schedulingSpecId));
final var expectedMsg = "Scheduling returned bad status failed with reason {\"data\":[{\"errors\":["
+ "{\"location\":{\"column\":1,\"line\":1},\"message\":\"TypeError: TS2306 No default "
+ "export. Expected a default export function with the signature:";
if (!error.getMessage().contains(expectedMsg)) {
throw error;
}
} finally {
hasura.deleteSchedulingGoal(goalId);
}
}

@Test
void schedulingIgnoreDisabledGoals() throws IOException {
// Add a problematic goal to the spec, then disable it
final int problemGoalId = hasura.createSchedulingSpecGoal(
"bad goal",
"error :-(",
"Goal that won't compile",
schedulingSpecId,
0);
try {
hasura.updateSchedulingSpecEnabled(schedulingSpecId, problemGoalId, false);

// Schedule -- Validate that the plan didn't change
hasura.awaitScheduling(schedulingSpecId);
assertEquals(0, hasura.getPlan(planId).activityDirectives().size());

// Enable disabled constraint
hasura.updateSchedulingSpecEnabled(schedulingSpecId, problemGoalId, true);

// Schedule -- Assert Fail
final var error = Assertions.assertThrows(
AssertionFailedError.class,
() -> hasura.awaitScheduling(schedulingSpecId));
final var expectedMsg = "Scheduling returned bad status failed with reason {\"data\":[{\"errors\":["
+ "{\"location\":{\"column\":1,\"line\":1},\"message\":\"TypeError: TS2306 No default "
+ "export. Expected a default export function with the signature:";
if (!error.getMessage().contains(expectedMsg)) {
throw error;
}
} finally {
hasura.deleteSchedulingGoal(problemGoalId);
}
}
}
}
Loading

0 comments on commit b2c680e

Please sign in to comment.