Skip to content

Commit

Permalink
Move to using "well-known" SkyFunctionNames in tests exercising graph
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=105539869
  • Loading branch information
michajlo authored and laszlocsomor committed Oct 16, 2015
1 parent 629a7c4 commit 6630426
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1513,8 +1513,8 @@ private ErrorInfo checkForCycles(SkyKey root, ValueVisitor visitor, boolean keep
// graph stack.
while (!toVisit.isEmpty()) {
SkyKey key = toVisit.pop();
NodeEntry entry = graph.get(key);

NodeEntry entry;
if (key == CHILDREN_FINISHED) {
// A marker node means we are done with all children of a node. Since all nodes have
// errors, we must have found errors in the children when that happens.
Expand Down Expand Up @@ -1548,6 +1548,8 @@ private ErrorInfo checkForCycles(SkyKey root, ValueVisitor visitor, boolean keep
SkyFunctionEnvironment env = new SkyFunctionEnvironment(key, directDeps, visitor);
env.setError(ErrorInfo.fromChildErrors(key, errorDeps));
env.commit(/*enqueueParents=*/false);
} else {
entry = graph.get(key);
}

Preconditions.checkNotNull(entry, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public SkyFunctionName load(String name) {
}
});

/**
* A well-known key type intended for testing only. The associated SkyKey should have a String
* argument.
*/
// Needs to be after the cache is initialized.
public static final SkyFunctionName FOR_TESTING = SkyFunctionName.create("FOR_TESTING");

/** Create a SkyFunctionName identified by {@code name}. */
public static SkyFunctionName create(String name) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
/** Base class for concurrency sanity tests on {@link EvaluableGraph} implementations. */
public abstract class GraphConcurrencyTest {

private static final SkyFunctionName SKY_FUNCTION_NAME =
SkyFunctionName.create("GraphConcurrencyTestKey");
private static final SkyFunctionName SKY_FUNCTION_NAME = SkyFunctionName.FOR_TESTING;
private ProcessableGraph graph;
private TestRunnableWrapper wrapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/
public class GraphTester {

public static final SkyFunctionName NODE_TYPE = SkyFunctionName.create("Type");
public static final SkyFunctionName NODE_TYPE = SkyFunctionName.FOR_TESTING;

private final Map<SkyKey, TestFunction> values = new HashMap<>();
private final Set<SkyKey> modifiedValues = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ public void manyValuesDependOnSingleValue() throws Exception {

EvaluationResult<StringValue> result = tester.eval(/*keep_going=*/false, values);
for (int i = 0; i < values.length; i++) {
SkyValue actual = result.get(new SkyKey(GraphTester.NODE_TYPE, values[i]));
SkyValue actual = result.get(toSkyKey(values[i]));
assertEquals(new StringValue("leaf"), actual);
}

Expand All @@ -663,7 +663,7 @@ public void manyValuesDependOnSingleValue() throws Exception {
tester.invalidate();
result = tester.eval(/*keep_going=*/false, values);
for (int i = 0; i < values.length; i++) {
SkyValue actual = result.get(new SkyKey(GraphTester.NODE_TYPE, values[i]));
SkyValue actual = result.get(toSkyKey(values[i]));
assertEquals("Run " + j + ", value " + i, new StringValue("other" + j), actual);
}
}
Expand All @@ -679,7 +679,7 @@ public void singleValueDependsOnManyValues() throws Exception {
tester.set(values[i], new StringValue(values[i]));
expected.append(values[i]);
}
SkyKey rootKey = new SkyKey(GraphTester.NODE_TYPE, "root");
SkyKey rootKey = toSkyKey("root");
TestFunction value = tester.getOrCreate(rootKey)
.setComputedValue(CONCATENATE);
for (int i = 0; i < values.length; i++) {
Expand Down Expand Up @@ -928,7 +928,7 @@ public void parentOfCycleAndTransientNotTransient() throws Exception {
.that(errorInfo.getCycleInfo())
.containsExactly(
new CycleInfo(ImmutableList.of(top), ImmutableList.of(cycleKey1, cycleKey2)));
assertThat(errorInfo.getException()).hasMessage("Type:errorKey");
assertThat(errorInfo.getException()).hasMessage(NODE_TYPE.getName() + ":errorKey");
assertThat(errorInfo.getRootCauseOfException()).isEqualTo(errorKey);
}

Expand Down Expand Up @@ -1895,7 +1895,7 @@ public void singleValueDependsOnManyDirtyValues() throws Exception {
tester.set(values[i], new StringValue(valueName));
expected.append(valueName);
}
SkyKey topKey = new SkyKey(GraphTester.NODE_TYPE, "top");
SkyKey topKey = toSkyKey("top");
TestFunction value = tester.getOrCreate(topKey)
.setComputedValue(CONCATENATE);
for (int i = 0; i < values.length; i++) {
Expand Down Expand Up @@ -3145,7 +3145,9 @@ public void valueInjectionOverValueWithDeps() throws Exception {
tester.evalAndGet("value");
Assert.fail("injection over value with deps should have failed");
} catch (IllegalStateException e) {
assertEquals("existing entry for Type:value has deps: [Type:other]", e.getMessage());
assertThat(e).hasMessage(
"existing entry for " + NODE_TYPE.getName() + ":value has deps: "
+ "[" + NODE_TYPE.getName() + ":other]");
}
}

Expand All @@ -3162,7 +3164,9 @@ public void valueInjectionOverEqualValueWithDeps() throws Exception {
tester.evalAndGet("value");
Assert.fail("injection over value with deps should have failed");
} catch (IllegalStateException e) {
assertEquals("existing entry for Type:value has deps: [Type:other]", e.getMessage());
assertThat(e).hasMessage(
"existing entry for " + NODE_TYPE.getName() + ":value has deps: "
+ "[" + NODE_TYPE.getName() + ":other]");
}
}

Expand Down Expand Up @@ -3648,7 +3652,7 @@ public <T extends SkyValue> EvaluationResult<T> eval(boolean keepGoing, String..

public SkyValue evalAndGet(boolean keepGoing, String key)
throws InterruptedException {
return evalAndGet(keepGoing, new SkyKey(NODE_TYPE, key));
return evalAndGet(keepGoing, toSkyKey(key));
}

public SkyValue evalAndGet(String key) throws InterruptedException {
Expand All @@ -3671,7 +3675,7 @@ public ErrorInfo evalAndGetError(SkyKey key) throws InterruptedException {
}

public ErrorInfo evalAndGetError(String key) throws InterruptedException {
return evalAndGetError(new SkyKey(NODE_TYPE, key));
return evalAndGetError(toSkyKey(key));
}

@Nullable
Expand All @@ -3681,7 +3685,7 @@ public SkyValue getExistingValue(SkyKey key) {

@Nullable
public SkyValue getExistingValue(String key) {
return getExistingValue(new SkyKey(NODE_TYPE, key));
return getExistingValue(toSkyKey(key));
}
}
}

0 comments on commit 6630426

Please sign in to comment.