spec/javascript/engine_spec.js in faye-0.7.2 vs spec/javascript/engine_spec.js in faye-0.8.0

- old
+ new

@@ -10,15 +10,15 @@ }, connect: function(name, engine, resume) { var clientId = this._clients[name] var inboxes = this._inboxes - engine.connect(clientId, {}, function(m) { - Faye.each(m, function(message) { - delete message.id - inboxes[name].push(message) - }) + engine.connect(clientId, {}, function(messages) { + for (var i = 0, n = messages.length; i < n; i++) { + delete messages[i].id + inboxes[name].push(messages[i]) + } }) setTimeout(resume, 10) }, destroy_client: function(name, resume) { @@ -30,11 +30,11 @@ resume() }, check_num_clients: function(n, resume) { var ids = new JS.Set() - Faye.each(this._clients, function(name, id) { ids.add(id) }) + for (var key in this._clients) ids.add(this._clients[key]) this.assertEqual(n, ids.count()) resume() }, check_client_exists: function(name, exists, resume) { @@ -53,14 +53,14 @@ this.engine.unsubscribe(this._clients[name], channel, resume) }, publish: function(messages, resume) { messages = [].concat(messages) - Faye.each(messages, function(message) { - message = Faye.extend({id: Faye.random()}, message) + for (var i = 0, n = messages.length; i < n; i++) { + var message = Faye.extend({id: Faye.random()}, messages[i]) this.engine.publish(message) - }, this) + } setTimeout(resume, 20) }, publish_by: function(name, message, resume) { message = Faye.extend({clientId: this._clients[name], id: Faye.random()}, message) @@ -106,33 +106,22 @@ }, check_different_messages: function(a, b, resume) { this.assertNotSame(this._inboxes[a][0], this._inboxes[b][0]) resume() - }, - - clean_redis_db: function(resume) { - this.engine.disconnect() - var redis = require('redis').createClient(6379, 'localhost', {no_ready_check: true}) - redis.auth(this.engineOpts.password) - redis.flushall(function() { - redis.end() - resume() - }) } }) JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this) { - include(JS.Test.Helpers) - - define("create_engine", function() { with(this) { - var opts = Faye.extend(options(), engineOpts) - return new engineKlass(opts) - }}) - sharedExamplesFor("faye engine", function() { with(this) { + include(JS.Test.Helpers) include(EngineSteps) + + define("create_engine", function() { with(this) { + var opts = Faye.extend(options(), engineOpts) + return new Faye.Engine.Proxy(opts) + }}) define("options", function() { return {timeout: 1} }) before(function() { with(this) { this.engine = create_engine() @@ -388,11 +377,18 @@ }}) }}) }}) sharedBehavior("distributed engine", function() { with(this) { + include(JS.Test.Helpers) include(EngineSteps) + + define("create_engine", function() { with(this) { + var opts = Faye.extend(options(), engineOpts) + return new Faye.Engine.Proxy(opts) + }}) + define("options", function() { return {timeout: 1} }) before(function() { with(this) { this.left = create_engine() this.right = create_engine() @@ -414,39 +410,8 @@ expect_message("alice", [{channel: "/foo", data: "first"}]) publish({channel: "/foo", data: "second"}) connect("alice", right) expect_message("alice", [{channel: "/foo", data: "first"}, {channel: "/foo", data: "second"}]) }}) - }}) - }}) - - describe("Faye.Engine.Memory", function() { with(this) { - before(function() { - this.engineKlass = Faye.Engine.Memory - this.engineOpts = {} - }) - - itShouldBehaveLike("faye engine") - }}) - - describe("Faye.Engine.Redis", function() { with(this) { - before(function() { - this.engineKlass = Faye.Engine.Redis - this.engineOpts = {password: "foobared", namespace: new Date().getTime().toString()} - }) - after(function() { this.clean_redis_db() }) - - itShouldBehaveLike("faye engine") - - describe("distribution", function() { with(this) { - itShouldBehaveLike("distributed engine") - }}) - - describe("using a Unix socket", function() { with(this) { - before(function() { with(this) { - this.engineOpts.socket = "/tmp/redis.sock" - }}) - - itShouldBehaveLike("faye engine") }}) }}) }})