Skip to content

Commit

Permalink
add multi-thread command line
Browse files Browse the repository at this point in the history
  • Loading branch information
winsonwq committed Jun 8, 2014
1 parent ad27a97 commit 3ea8275
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
3 changes: 3 additions & 0 deletions bin/viffs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../lib/viffs.js')
1 change: 1 addition & 0 deletions gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = (grunt) ->
'lib/testcase.js': 'src/testcase.coffee',
'lib/capability.js': 'src/capability.coffee',
'lib/resemble.js': 'src/resemble.coffee',
'lib/viffs.js': 'src/viffs.coffee',
'lib/canvas.drawimage.js': 'src/canvas.drawimage.coffee',
'lib/image.dataurl.helper.js': 'src/image.dataurl.helper.coffee',
'test/build/comparison_test.js': 'test/src/comparison_test.coffee',
Expand Down
21 changes: 10 additions & 11 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ return console.log config if _.isString config

viff = new Viff config.seleniumHost

if config.reportFormat == 'file'
consoleStatus viff
consoleStatus viff

# clean the images and report.json
viff.on 'before', (cases) -> imgGen.reset();
# clean the images and report.json
viff.on 'before', (cases) -> imgGen.reset();

# generate images by each case
viff.on 'afterEach', (_case, duration) -> imgGen.generateByCase _case if duration != 0
# generate images by each case
viff.on 'afterEach', (_case, duration) -> imgGen.generateByCase _case if duration != 0

# generate report.json
viff.on 'after', (cases, duration) ->
imgGen.generateReport cases
resemble.exit()
partialCanvas.exit()
# generate report.json
viff.on 'after', (cases, duration) ->
imgGen.generateReport cases
resemble.exit()
partialCanvas.exit()

cases = Viff.constructCases config.browsers, config.envHosts, config.paths
viff.run cases
15 changes: 7 additions & 8 deletions src/viff.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class Viff extends EventEmitter

cases

@split: (cases, count) ->
groups = []
groups.push [] while count--
groups[idx % groups.length].push _case for idx, _case of cases

groups

run: (cases, callback) ->
defer = Q.defer()
defer.promise.done callback
Expand All @@ -72,14 +79,6 @@ class Viff extends EventEmitter
@emit 'before', cases
start = Date.now()

endQueue = (index) ->
if index == cases.length - 1
endTime = Date.now() - start
that.emit 'after', cases, endTime
defer.resolve [cases, endTime]

that.closeDrivers()

async.eachSeries cases, (_case, next) ->
startcase = Date.now()
that.emit 'beforeEach', _case, 0
Expand Down
32 changes: 32 additions & 0 deletions src/viffs.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
_ = require 'underscore'

Viff = require './viff.js'
processArgs = require './process.argv.js'
consoleStatus = require './console.status.js'
imgGen = require './image.generator'
resemble = require './resemble'
partialCanvas = require './canvas.drawimage'

config = processArgs process.argv

return console.log config if _.isString config

count = 3

cases = Viff.constructCases config.browsers, config.envHosts, config.paths
testGroups = Viff.split cases, count
resolvedCases = []

imgGen.reset();

for group in testGroups
viff = new Viff config.seleniumHost
viff.on 'afterEach', (_case, duration) -> imgGen.generateByCase _case if duration != 0
consoleStatus viff

viff.run group, ([cases, endTime]) ->
resolvedCases = resolvedCases.concat cases
unless --count
imgGen.generateReport resolvedCases
resemble.exit()
partialCanvas.exit()
6 changes: 6 additions & 0 deletions test/src/viff.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,9 @@ describe 'viff', ->
cases = Viff.constructCases(browsers, @config.compare, @links)
cases.length.should.equal 6
_.first(cases).from.name.should.equal 'build'

it 'should split cases to groups according to amount of instances', () ->
cases = Viff.constructCases(@config.browsers, @config.compare, @links)
groups = Viff.split cases, 3
groups[0].length.should.equal 2
groups[1].length.should.equal 1

0 comments on commit 3ea8275

Please sign in to comment.