forked from basecamp/pow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_daemon.coffee
53 lines (43 loc) · 1.54 KB
/
test_daemon.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
net = require "net"
path = require "path"
{testCase} = require "nodeunit"
{Configuration, Daemon} = require ".."
{prepareFixtures, fixturePath, touch} = require "./lib/test_helper"
module.exports = testCase
setUp: (proceed) ->
prepareFixtures proceed
"start and stop": (test) ->
test.expect 2
configuration = new Configuration POW_HOST_ROOT: fixturePath("tmp"), POW_HTTP_PORT: 0, POW_DNS_PORT: 0
daemon = new Daemon configuration
daemon.start()
daemon.on "start", ->
test.ok daemon.started
daemon.stop()
daemon.on "stop", ->
test.ok !daemon.started
test.done()
"start rolls back when it can't boot a server": (test) ->
test.expect 2
server = net.createServer()
server.listen 0, ->
port = server.address().port
configuration = new Configuration POW_HOST_ROOT: fixturePath("tmp"), POW_HTTP_PORT: port
daemon = new Daemon configuration
daemon.start()
daemon.on "error", (err) ->
test.ok err
test.ok !daemon.started
server.close()
test.done()
"touching restart.txt removes the file and emits a restart event": (test) ->
test.expect 1
restartFilename = path.join fixturePath("tmp"), "restart.txt"
configuration = new Configuration POW_HOST_ROOT: fixturePath("tmp"), POW_HTTP_PORT: 0, POW_DNS_PORT: 0
daemon = new Daemon configuration
daemon.start()
touch restartFilename, ->
daemon.once "restart", ->
path.exists restartFilename, (exists) ->
test.ok !exists
test.done()