Skip to content

Commit

Permalink
Minor modifications to smoke test. Fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
majek committed Oct 7, 2011
1 parent f93b8c7 commit 8dc1e91
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
5 changes: 2 additions & 3 deletions client.coffee
Expand Up @@ -3,7 +3,7 @@ common = require('./common')

exports.GenericClient = class GenericClient extends events.EventEmitter
constructor: (url) ->
@id = ('' + Math.random()).slice(2)
@id = ('' + Math.random()).slice(2, 16)
@url = url + '/0/' + @id
@buffer = []
@is_opened = false
Expand All @@ -19,9 +19,8 @@ exports.GenericClient = class GenericClient extends events.EventEmitter
@is_opened = true
@emit('open')
else
console.log('Already open')
@is_closed = true
@emit('close', 1000, 'error')
@emit('close', 1000, 'Connection prematurely closed!')
when 'h' then null
when 'a'
for m in JSON.parse(payload)
Expand Down
5 changes: 5 additions & 0 deletions common.coffee
Expand Up @@ -21,6 +21,7 @@ exports.HttpRequest = class HttpRequest extends events.EventEmitter
@req.socket.setTimeout(60000)
@status = @res.statusCode
@headers = @res.headers
@emit('start')
@res.on 'data', (chunk) =>
chunk = chunk.toString('utf-8')
@chunks.push(chunk)
Expand All @@ -33,6 +34,7 @@ exports.HttpRequest = class HttpRequest extends events.EventEmitter

@req.on 'error', (e) =>
console.log('error!',e)
process.exit(1)
if (body or '').length > 0
@req.end(body, 'utf-8')
else
Expand Down Expand Up @@ -74,3 +76,6 @@ exports.StdDev = class StdDev
avg = @avg()
variance = (@sum_sq / @count) - (avg * avg)
return Math.sqrt(variance)

exports.now = ->
(new Date()).getTime()
25 changes: 11 additions & 14 deletions smoke-test.coffee
Expand Up @@ -7,15 +7,13 @@ common = require('./common')


url = 'http://localhost:8080/echo'
count = 200
hz = 5
seconds = 5
test = 'idle'
transport = 'xhr_polling'
count = 500
hz = 1
seconds = 20

console.log(' [*] Connecting to ' + url +
' (connections:' + count +
', test:' + test + ', transport:' + transport + ')')
' (count:' + count +
', hz:' + hz + ', seconds:' + seconds + ')')

connected_counter = 0
connected = ->
Expand All @@ -33,8 +31,6 @@ closed = ->
' dev=', stats.dev(),
' (' + stats.count + ' data points)')

now = ->
(new Date()).getTime()

stats = new common.StdDev()

Expand All @@ -45,16 +41,17 @@ conns = for i in [0...count]
conn.on('open', connected)
conn.on 'message', (t0) ->
c -= 1
delay = now() - Number(t0)
delay = common.now() - Number(t0)
stats.add(delay)
if c > 0
go = -> conn.send('' + now())
go = -> conn.send('' + common.now())
setTimeout(go, 1000/hz)
else
closed()
conn.close()
conn.on 'close', -> console.log('ERROR')
conn.on 'close', (_, reason) ->
closed()
console.log('ERROR', reason)
return ->
conn.send('' + now())

conn.send('' + common.now())

0 comments on commit 8dc1e91

Please sign in to comment.