Skip to content

Commit

Permalink
better smoke testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed May 26, 2024
1 parent 3c9e0ed commit 629f22b
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions model/src/test/java/com/salesforce/apollo/model/DomainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static com.salesforce.apollo.choam.Session.retryNesting;
import static java.util.concurrent.CompletableFuture.allOf;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -88,22 +88,29 @@ public static void smoke(Oracle oracle) throws Exception {

// Map direct edges. Transitive edges added as a side effect

allOf(retryNesting(() -> oracle.map(helpDeskMembers, adminMembers), 3),
retryNesting(() -> oracle.map(ali, adminMembers), 3), retryNesting(() -> oracle.map(ali, userMembers), 3),
retryNesting(() -> oracle.map(burcu, userMembers), 3),
retryNesting(() -> oracle.map(can, userMembers), 3),
retryNesting(() -> oracle.map(managerMembers, userMembers), 3),
retryNesting(() -> oracle.map(technicianMembers, userMembers), 3),
retryNesting(() -> oracle.map(demet, helpDeskMembers), 3),
retryNesting(() -> oracle.map(egin, helpDeskMembers), 3),
retryNesting(() -> oracle.map(egin, userMembers), 3),
retryNesting(() -> oracle.map(fuat, managerMembers), 3),
retryNesting(() -> oracle.map(gl, managerMembers), 3),
retryNesting(() -> oracle.map(hakan, technicianMembers), 3),
retryNesting(() -> oracle.map(irmak, technicianMembers), 3),
retryNesting(() -> oracle.map(abcTechMembers, technicianMembers), 3),
retryNesting(() -> oracle.map(flaggedTechnicianMembers, technicianMembers), 3),
retryNesting(() -> oracle.map(jale, abcTechMembers), 3)).get(60, TimeUnit.SECONDS);
var countDown = new CountDownLatch(17);

retryNesting(() -> oracle.map(helpDeskMembers, adminMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(ali, adminMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(ali, userMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(burcu, userMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(can, userMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(managerMembers, userMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(technicianMembers, userMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(demet, helpDeskMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(egin, helpDeskMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(egin, userMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(fuat, managerMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(gl, managerMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(hakan, technicianMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(irmak, technicianMembers), 3).whenComplete((_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(abcTechMembers, technicianMembers), 3).whenComplete(
(_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(flaggedTechnicianMembers, technicianMembers), 3).whenComplete(
(_, _) -> countDown.countDown());
retryNesting(() -> oracle.map(jale, abcTechMembers), 3).whenComplete((_, _) -> countDown.countDown());

countDown.await(120, TimeUnit.SECONDS);

// Protected resource namespace
var docNs = Oracle.namespace("Document");
Expand All @@ -114,7 +121,7 @@ public static void smoke(Oracle oracle) throws Exception {

// Users can View Document 123
Assertion tuple = userMembers.assertion(object123View);
retryNesting(() -> oracle.add(tuple), 3).get();
retryNesting(() -> oracle.add(tuple), 3).get(120, TimeUnit.SECONDS);

// Direct subjects that can View the document
var viewers = oracle.read(object123View);
Expand All @@ -128,7 +135,7 @@ public static void smoke(Oracle oracle) throws Exception {

// Assert flagged technicians can directly view the document
Assertion grantTechs = flaggedTechnicianMembers.assertion(object123View);
retryNesting(() -> oracle.add(grantTechs), 3).get();
retryNesting(() -> oracle.add(grantTechs), 3).get(120, TimeUnit.SECONDS);

// Now have 2 direct subjects that can view the doc
viewers = oracle.read(object123View);
Expand Down Expand Up @@ -167,22 +174,22 @@ public static void smoke(Oracle oracle) throws Exception {
assertFalse(oracle.check(object123View.assertion(helpDeskMembers)));

// Remove them
retryNesting(() -> oracle.remove(abcTechMembers, technicianMembers), 3).get();
retryNesting(() -> oracle.remove(abcTechMembers, technicianMembers), 3).get(120, TimeUnit.SECONDS);

assertFalse(oracle.check(object123View.assertion(jale)));
assertTrue(oracle.check(object123View.assertion(egin)));
assertFalse(oracle.check(object123View.assertion(helpDeskMembers)));

// Remove our assertion
retryNesting(() -> oracle.delete(tuple), 3).get();
retryNesting(() -> oracle.delete(tuple), 3).get(120, TimeUnit.SECONDS);

assertFalse(oracle.check(object123View.assertion(jale)));
assertFalse(oracle.check(object123View.assertion(egin)));
assertFalse(oracle.check(object123View.assertion(helpDeskMembers)));

// Some deletes
retryNesting(() -> oracle.delete(abcTechMembers), 3).get();
retryNesting(() -> oracle.delete(flaggedTechnicianMembers), 3).get();
retryNesting(() -> oracle.delete(abcTechMembers), 3).get(120, TimeUnit.SECONDS);
retryNesting(() -> oracle.delete(flaggedTechnicianMembers), 3).get(120, TimeUnit.SECONDS);
}

@AfterEach
Expand Down

0 comments on commit 629f22b

Please sign in to comment.