This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(blocking): Send block for all requests if memcache is down
- Loading branch information
Showing
2 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* Any copyright is dedicated to the Public Domain. | ||
* http://creativecommons.org/publicdomain/zero/1.0/ */ | ||
|
||
var test = require('tap').test | ||
var restify = require('restify') | ||
var TestServer = require('../test_server') | ||
|
||
var TEST_EMAIL = 'test@example.com' | ||
var TEST_IP = '192.0.2.1' | ||
|
||
var config = { | ||
listen: { | ||
port: 7000 | ||
} | ||
} | ||
|
||
process.env.MEMCACHE_ADDRESS = '128.0.0.1:12131' | ||
|
||
var testServer = new TestServer(config) | ||
|
||
test( | ||
'startup', | ||
function (t) { | ||
testServer.start(function (err) { | ||
t.type(testServer.server, 'object', 'test server was started') | ||
t.notOk(err, 'no errors were returned') | ||
t.end() | ||
}) | ||
} | ||
) | ||
|
||
|
||
var client = restify.createJsonClient({ | ||
url: 'http://127.0.0.1:' + config.listen.port | ||
}) | ||
|
||
test( | ||
'request with disconnected memcache', | ||
function (t) { | ||
client.post('/check', { email: TEST_EMAIL, ip: TEST_IP, action: 'someRandomAction' }, | ||
function (err, req, res, obj) { | ||
t.equal(res.statusCode, 200, 'check worked') | ||
t.equal(obj.block, true, 'request was blocked') | ||
t.equal(obj.retryAfter, 900, 'retry after') | ||
t.end() | ||
} | ||
) | ||
} | ||
) | ||
|
||
test( | ||
'teardown', | ||
function (t) { | ||
testServer.stop() | ||
t.equal(testServer.server.killed, true, 'test server has been killed') | ||
t.end() | ||
} | ||
) |