Merge pull request #1850 from brendandahl/intex-better-isolate-test

Use a more predicable isolate test with assertions.
This commit is contained in:
Myk Melez 2015-08-28 11:59:29 -07:00
Родитель b76fc53d65 2f77cbc84f
Коммит eb53a6975c
5 изменённых файлов: 69 добавлений и 90 удалений

Просмотреть файл

@ -178,7 +178,7 @@ function syncFS() {
});
}
casper.test.begin("unit tests", 39 + gfxTests.length, function(test) {
casper.test.begin("unit tests", 40 + gfxTests.length, function(test) {
casper.start("data:text/plain,start");
casper.page.onLongRunningScript = function(message) {
@ -238,44 +238,10 @@ casper.test.begin("unit tests", 39 + gfxTests.length, function(test) {
.thenOpen("http://localhost:8000/index.html?main=tests/isolate/TestIsolate&logLevel=info&logConsole=web,page,raw")
.withFrame(0, function() {
casper.waitForText("DONE", function() {
var output = this.fetchText('#raw-console');
var expectedOutput = [
"I 0: m",
"I 2 0 a ma",
"I 1: ma",
"I 2: 2",
"I 3: 1 isolate",
"I 4: Isolate ID correct",
"I 5: 4",
"I 6: 5",
"I 7: 1 isolate",
"I 8: ma",
"I 9: ma",
"I 10: 3 isolates",
"I 5 0 2 m2",
"I 4 0 1 m1",
"I 11: ma",
"I 12: 1 isolate",
"I 13: Isolates terminated",
"I 2 1 r mar",
"I 14: mar",
"I 2 2 c marc",
"I 15: marc",
"I 16: Main isolate still running",
"I DONE",
"",
];
output = output.split("\n").sort();
expectedOutput.sort();
test.assert(expectedOutput.length === output.length, "Same number of lines output.");
var allMatch = true;
for (var i = 0; i < expectedOutput.length; i++) {
if (expectedOutput[i] !== output[i]) {
allMatch = false;
break;
}
}
test.assert(allMatch, "All lines are contained within output.");
test.assertTextDoesntExist("FAIL");
// Two sanity checks to make sure the two isolates ran.
test.assertTextExists("PASS First isolate static value is correct.");
test.assertTextExists("PASS Second isolate static value is correct.");
});
});

Просмотреть файл

@ -0,0 +1,25 @@
package gnu.testlet;
import gnu.testlet.TestHarness;
public class DumpTestHarness extends TestHarness {
public int pass = 0;
public int fail = 0;
private String note = "";
public void check(boolean ok) {
if (ok) {
pass++;
System.out.println("PASS " + note);
} else {
fail++;
System.out.println("FAIL " + note);
}
note = "";
}
public void todo(boolean ok) { throw new UnsupportedOperationException(); }
public void debug(String msg) { }
public void setNote(String note) {
this.note = note;
}
}

Просмотреть файл

@ -204,6 +204,8 @@ public abstract class TestHarness {
public TestHarness(Display d) {
display = d;
}
public TestHarness() {
}
public void setScreenAndWait(Displayable s) {
display.setCurrent(s);

Просмотреть файл

@ -1,13 +1,22 @@
package tests.isolate;
import com.sun.cldc.isolate.*;
import gnu.testlet.DumpTestHarness;
public class IsolatedClass {
static public String val = "m";
static public int testRun = 0;
static public String val = "a";
public static void main(String args[]) {
DumpTestHarness th = new DumpTestHarness();
val += args[0];
System.out.println(Isolate.currentIsolate().id() + " " + (testRun++) + " " + args[0] + " " + val);
if (args.length > 1) {
if (args[0].equals("1")) {
th.check(val, "a1", "First isolate static value is correct.");
} else if (args[0].equals("2")) {
th.check(val, "a2", "Second isolate static value is correct.");
} else {
th.fail("Bad arg value: " + args[0]);
}
}
}
}

Просмотреть файл

@ -2,88 +2,65 @@ package tests.isolate;
import com.sun.cldc.isolate.*;
import tests.isolate.IsolatedClass;
import gnu.testlet.DumpTestHarness;
import java.lang.String;
public class TestIsolate {
static int dumpNumber = 0;
public static void dump(String s) {
System.out.println((dumpNumber++) + ": " + s);
}
public static void dump(int s) {
dump(s + "");
}
public static void main(String args[]) {
dump(IsolatedClass.val);
DumpTestHarness th = new DumpTestHarness();
th.check(IsolatedClass.val, "a", "Initial IsolatedClass static value is correct.");
new IsolatedClass().main(new String[] { "a" } );
new IsolatedClass().main(new String[] { "b" } );
dump(IsolatedClass.val);
th.check(IsolatedClass.val, "ab", "IsolatedClass static val append works.");
Isolate myIso = Isolate.currentIsolate();
dump(myIso.id());
int myIsoId = myIso.id();
th.check(myIsoId > -1, "Valid isolate ID.");
Isolate[] isolates = Isolate.getIsolates();
if (isolates.length == 1) {
dump("1 isolate");
}
th.check(isolates.length == 1, "Only one isolate exists.");
if (isolates[0].id() == myIso.id()) {
dump("Isolate ID correct");
}
th.check(isolates[0].id() == myIso.id(), "Isolate ID is correct.");
try {
Isolate iso1 = new Isolate("tests.isolate.IsolatedClass", new String[] { "1" });
Isolate iso2 = new Isolate("tests.isolate.IsolatedClass", new String[] { "2" });
Isolate iso1 = new Isolate("tests.isolate.IsolatedClass", new String[] { "1", "new isolate" });
Isolate iso2 = new Isolate("tests.isolate.IsolatedClass", new String[] { "2", "new isolate" });
dump(iso1.id());
dump(iso2.id());
int iso1Id = iso1.id();
th.check(iso1Id > myIsoId, "First isolate id is larger than main isolate id.");
th.check(iso2.id() > iso1Id, "Second isolate id is larger than first isolate id.");
if (Isolate.getIsolates().length == 1) {
dump("1 isolate");
}
th.check(Isolate.getIsolates().length, 1, "1 isolate started.");
iso1.start();
dump(IsolatedClass.val);
th.check(IsolatedClass.val, "ab", "IsolatedClass static value not modified by iso1 starting.");
iso2.start();
th.check(IsolatedClass.val, "ab", "IsolatedClass static value not modified by iso2 starting.");
dump(IsolatedClass.val);
if (Isolate.getIsolates().length == 3) {
dump("3 isolates");
}
th.check(Isolate.getIsolates().length, 3, "3 isolates created.");
iso1.waitForExit();
iso2.waitForExit();
th.check(IsolatedClass.val, "ab", "IsolatedClass static value not modified by new isolates after exit.");
dump(IsolatedClass.val);
th.check(Isolate.getIsolates().length, 1, "1 isolate left.");
if (Isolate.getIsolates().length == 1) {
dump("1 isolate");
}
if (iso1.isTerminated() && iso2.isTerminated()) {
dump("Isolates terminated");
}
th.check(iso1.isTerminated(), "iso1 is terminated.");
th.check(iso2.isTerminated(), "iso2 is terminated.");
} catch(Exception e) {
e.printStackTrace();
th.fail("Exception: " + e);
}
new IsolatedClass().main(new String[] { "r" });
dump(IsolatedClass.val);
new IsolatedClass().main(new String[] { "c" });
dump(IsolatedClass.val);
th.check(IsolatedClass.val, "abc", "IsolatedClass static val append still works.");
if (!myIso.isTerminated()) {
dump("Main isolate still running");
}
th.check(!myIso.isTerminated(), "Main isolate still running");
System.out.println("DONE");
}