2016-02-03 02:11:50 +00:00
|
|
|
"use strict";
|
|
|
|
|
2016-01-31 22:48:00 +00:00
|
|
|
var expect = require('expect.js');
|
2016-02-12 04:56:42 +00:00
|
|
|
var Immutable = require('immutable');
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
var Syndicate = require('../src/main.js');
|
2016-04-07 07:42:54 +00:00
|
|
|
var Dataspace = Syndicate.Dataspace;
|
2016-02-12 04:56:42 +00:00
|
|
|
var Patch = Syndicate.Patch;
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
var __ = Syndicate.__;
|
|
|
|
var _$ = Syndicate._$;
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
function configurationTrace(bootConfiguration) {
|
|
|
|
var eventLog = [];
|
|
|
|
function trace(item) {
|
|
|
|
eventLog.push(item);
|
|
|
|
}
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
var G = new Syndicate.Ground(function () {
|
|
|
|
bootConfiguration(trace);
|
|
|
|
});
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
while (G.step()) {
|
|
|
|
// do nothing until G becomes inert
|
|
|
|
}
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
return eventLog;
|
|
|
|
}
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
function traceEvent(trace) {
|
|
|
|
return function(item) {
|
|
|
|
trace((item.type === "stateChange") ? item.patch.pretty() : item);
|
|
|
|
}
|
|
|
|
}
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
function checkTrace(bootConfiguration, expected) {
|
|
|
|
expect(configurationTrace(bootConfiguration)).to.eql(expected);
|
|
|
|
}
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
describe("configurationTrace", function() {
|
|
|
|
describe("with an inert configuration", function () {
|
|
|
|
it("should yield an empty trace", function () {
|
|
|
|
checkTrace(function (trace) {}, []);
|
|
|
|
});
|
|
|
|
});
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
describe("with a single trace in an inert configuration", function () {
|
|
|
|
it("should yield that trace", function () {
|
|
|
|
checkTrace(function (trace) { trace(1) }, [1]);
|
|
|
|
});
|
|
|
|
});
|
2016-01-31 22:48:00 +00:00
|
|
|
|
2016-02-12 04:56:42 +00:00
|
|
|
describe("with some traced communication", function () {
|
|
|
|
it("should yield an appropriate trace", function () {
|
|
|
|
checkTrace(function (trace) {
|
2016-04-07 07:42:54 +00:00
|
|
|
Dataspace.spawn({
|
2016-02-12 04:56:42 +00:00
|
|
|
boot: function () { return Syndicate.sub(__); },
|
|
|
|
handleEvent: traceEvent(trace)
|
|
|
|
});
|
2016-04-07 07:42:54 +00:00
|
|
|
Dataspace.send(123);
|
|
|
|
Dataspace.send(234);
|
2016-02-12 04:56:42 +00:00
|
|
|
}, ['<<<<<<<< Removed:\n'+
|
2016-05-08 15:11:16 +00:00
|
|
|
' ::: nothing\n'+
|
2016-02-12 04:56:42 +00:00
|
|
|
'======== Added:\n'+
|
2016-05-08 15:11:16 +00:00
|
|
|
' observe<1> ★ {[0]}\n'+
|
2016-02-12 04:56:42 +00:00
|
|
|
'>>>>>>>>',
|
|
|
|
Syndicate.message(123),
|
|
|
|
Syndicate.message(234)]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("nonempty initial routes", function () {
|
|
|
|
it("should be immediately signalled to the process", function () {
|
|
|
|
// Specifically, no Syndicate.updateRoutes([]) first.
|
|
|
|
checkTrace(function (trace) {
|
2016-04-07 07:42:54 +00:00
|
|
|
Dataspace.spawn({
|
2016-02-12 04:56:42 +00:00
|
|
|
boot: function () { return Patch.assert(["A", __]); },
|
|
|
|
handleEvent: function (e) {}
|
|
|
|
});
|
2016-04-07 07:42:54 +00:00
|
|
|
Dataspace.spawn({
|
2016-02-12 04:56:42 +00:00
|
|
|
boot: function () { return Patch.sub(["A", __]); },
|
|
|
|
handleEvent: traceEvent(trace)
|
|
|
|
});
|
|
|
|
}, ['<<<<<<<< Removed:\n'+
|
2016-05-08 15:11:16 +00:00
|
|
|
' ::: nothing\n'+
|
2016-02-12 04:56:42 +00:00
|
|
|
'======== Added:\n'+
|
2016-05-08 15:11:16 +00:00
|
|
|
' <2> "A" ★ {[0]}\n'+
|
2016-02-12 04:56:42 +00:00
|
|
|
'>>>>>>>>']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("nested actor with an echoey protocol", function () {
|
|
|
|
it("shouldn't see an echoed assertion", function () {
|
|
|
|
checkTrace(function (trace) {
|
2016-04-07 07:42:54 +00:00
|
|
|
Dataspace.spawn(new Dataspace(function () {
|
|
|
|
Dataspace.spawn({
|
2016-02-12 04:56:42 +00:00
|
|
|
boot: function () {
|
2016-04-07 07:42:54 +00:00
|
|
|
Dataspace.stateChange(Patch.retract("X", 1)); // happens after subs on next line!
|
2016-02-12 04:56:42 +00:00
|
|
|
return Patch.sub("X", 1).andThen(Patch.assert("X", 1));
|
|
|
|
},
|
|
|
|
handleEvent: traceEvent(trace)
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}, ['<<<<<<<< Removed:\n'+
|
2016-05-08 15:11:16 +00:00
|
|
|
' ::: nothing\n'+
|
2016-02-12 04:56:42 +00:00
|
|
|
'======== Added:\n'+
|
2016-05-10 04:40:53 +00:00
|
|
|
' at-meta<1> "X" {["meta"]}\n'+
|
2016-02-12 04:56:42 +00:00
|
|
|
'>>>>>>>>',
|
|
|
|
'<<<<<<<< Removed:\n'+
|
2016-05-10 04:40:53 +00:00
|
|
|
' at-meta<1> "X" {["meta"]}\n'+
|
2016-02-12 04:56:42 +00:00
|
|
|
'======== Added:\n'+
|
2016-05-08 15:11:16 +00:00
|
|
|
' ::: nothing\n'+
|
2016-02-12 04:56:42 +00:00
|
|
|
'>>>>>>>>']);
|
|
|
|
})
|
|
|
|
it("shouldn't see an echoed message", function () {
|
|
|
|
checkTrace(function (trace) {
|
2016-04-07 07:42:54 +00:00
|
|
|
Dataspace.spawn(new Dataspace(function () {
|
|
|
|
Dataspace.spawn({
|
2016-02-12 04:56:42 +00:00
|
|
|
boot: function () {
|
2016-04-07 07:42:54 +00:00
|
|
|
Dataspace.send("X", 1); // happens after subs on next line!
|
2016-05-08 15:11:16 +00:00
|
|
|
return Patch.sub("X", 1);
|
2016-02-12 04:56:42 +00:00
|
|
|
},
|
|
|
|
handleEvent: traceEvent(trace)
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}, [Syndicate.message(Patch.atMeta("X"))]);
|
|
|
|
});
|
|
|
|
it("shouldn't see an echoed assertion", function () {
|
|
|
|
});
|
|
|
|
});
|
2016-01-31 22:48:00 +00:00
|
|
|
|
|
|
|
// describe("actor with nonempty initial routes", function () {
|
|
|
|
// it("shouldn't see initial empty conversational context", function () {
|
|
|
|
// checkTrace(function (trace) {
|
2016-04-07 07:42:54 +00:00
|
|
|
// Dataspace.spawn({
|
2016-01-31 22:48:00 +00:00
|
|
|
// boot: function () { return [pub(["A", __])] },
|
|
|
|
// handleEvent: function (e) {
|
2016-04-07 07:42:54 +00:00
|
|
|
// Dataspace.spawn(new Actor(function () {
|
2016-01-31 22:48:00 +00:00
|
|
|
// Actor.observeAdvertisers(
|
|
|
|
// function () { return ["A", __] },
|
|
|
|
// { presence: "isPresent" },
|
|
|
|
// function () {
|
|
|
|
// trace(["isPresent", this.isPresent]);
|
|
|
|
// });
|
|
|
|
// }));
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }, [["isPresent", true]]);
|
|
|
|
// });
|
|
|
|
// });
|