From e45d8339c47d77fb9a6db48d3c66398091a89e22 Mon Sep 17 00:00:00 2001 From: Simon Tokumine Date: Mon, 9 Jul 2012 16:12:03 +0200 Subject: [PATCH] add event driven test when VarnishEmu server starts to listen --- test/acceptance/cache_validator.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/acceptance/cache_validator.js b/test/acceptance/cache_validator.js index 703410fa..b03f6d7e 100644 --- a/test/acceptance/cache_validator.js +++ b/test/acceptance/cache_validator.js @@ -4,7 +4,7 @@ require(__dirname + '/../test_helper'); var CacheValidator = require(__dirname + '/../../lib/cartodb/cache_validator'); var tests = module.exports = {}; -function VarnishEmu(on_cmd_recieved) { +function VarnishEmu(on_cmd_recieved, test_callback) { var self = this; var welcome_msg = 'hi, im a varnish emu, right?'; @@ -21,13 +21,20 @@ function VarnishEmu(on_cmd_recieved) { }); }); server.listen(1337, "127.0.0.1"); + + server.on('listening', function(){ + test_callback(); + }); } tests['should call purge on varnish when invalidate database'] = function() { - var varnish = new VarnishEmu(function(cmds) { + var varnish = new VarnishEmu( + function(cmds) { assert.ok(cmds.length == 1); assert.equal('purge obj.http.X-Cache-Channel ~ \"^test_db:(.*test_cache.*)|(table)$\"\n', cmds[0].toString('utf8')); + }, + function(){ + CacheValidator.init('localhost', 1337); + CacheValidator.invalidate_db('test_db', 'test_cache'); }); - CacheValidator.init('localhost', 1337); - CacheValidator.invalidate_db('test_db', 'test_cache'); }