-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhammer-time.js
executable file
·79 lines (69 loc) · 1.83 KB
/
hammer-time.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var minimist = require('minimist')
var log = require('npmlog')
var hammerTime = require('../')
var args
var host
var port = 80
var concurrent = 100
var frequency = 50
var duration = 60000
var generator
var start = (new Date()).getTime()
var verbose = false
var msgCount = 0
function usage () {
fs.createReadStream(path.join(__dirname, '../usage.txt')).pipe(process.stdout)
}
args = minimist(process.argv.slice(2))
host = args._[0]
if (args.version) {
var pkg = require(path.join(__dirname, '../package'))
log.info(pkg.name, 'version', pkg.version)
process.exit(0)
}
if (!host || args.help || args.h) {
usage()
process.exit(0)
}
port = args.port || args.p || port
concurrent = args.concurrent || args.c || concurrent
frequency = args.frequency || args.f || frequency
duration = args.duration || args.d || duration
generator = args.generator || args.g || generator
verbose = args.verbose || args.v || verbose
hammerTime(host, port, concurrent, frequency, duration, generator)
.on('start', function () {
if (verbose) {
log.info('hammer-time', 'Stop! Hammertime!')
}
})
.on('client-connected', function () {
if (verbose) {
log.info('hammer-time', 'Client connected')
}
})
.on('error', function (err) {
log.error('hammer-time', 'An error occurred')
log.error('hammer-time', err)
})
.on('disconnect', function () {
if (verbose) {
log.info('hammer-time', 'Client disconnected')
}
})
.on('message', function (msg) {
++msgCount
if (verbose) {
log.info('hammer-time', msg)
} else {
process.stdout.write('.')
}
})
.on('end', function () {
console.log()
log.info('hammer-time', 'Sent %j messages in %j seconds', msgCount, ((new Date()).getTime() - start) / 1000)
process.exit(0)
})