Skip to content

Commit

Permalink
add failing driver and server tests for circular objs over websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jun 12, 2019
1 parent 91c24aa commit 368ead8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ describe "driver/src/cypress/index", ->

done()

## https://github.com/cypress-io/cypress/issues/4346
it "can complete if a circular reference is sent", ->
foo = {
bar: {}
}

foo.bar.baz = foo

Cypress.backend("foo", foo)
.catch (e) ->
expect(e.message).to.eq('You requested a backend event we cannot handle: foo')

context ".isCy", ->
it "returns true on cy, cy chainable", ->
expect(Cypress.isCy(cy)).to.be.true
Expand Down Expand Up @@ -75,4 +87,4 @@ describe "driver/src/cypress/index", ->
fn = ->
Cypress.log({ message: 'My Log' })

expect(fn).to.not.throw()
expect(fn).to.not.throw()
16 changes: 16 additions & 0 deletions packages/server/test/unit/socket_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ describe "lib/socket", ->
afterEach ->
@client.disconnect()

## https://github.com/cypress-io/cypress/issues/4346
it "can emit a circular object without crashing", (done) ->
foo = {
bar: {}
}

foo.bar.baz = foo

## going to stub exec here just so we have something that we can
## control the resolved value of
sinon.stub(exec, 'run').resolves(foo)

@client.emit "backend:request", "exec", "quuz", (res) ->
expect(res).to.deep.eq(foo)
done()

context "on(automation:request)", ->
describe "#onAutomation", ->
before ->
Expand Down
37 changes: 37 additions & 0 deletions packages/server/timerfuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const _ = require('lodash')
const percentile = require('percentile')

// require('./timers/parent').fix()
console.log('running fuzz')
const N = 10000

let differences = []

_.times(N, () => {
const ms = 50 + (Math.random() * 1000) // between 0 and 1 minute
const started = new Date

setTimeout(() => {
const elapsed = new Date - started
const difference = elapsed - ms

differences.push(difference)

//console.log(`Expected: ${ms}ms\tActual: ${elapsed}ms\tDifference: ${difference}ms`)

if (differences.length === N) {
printSummary()
}
}, ms)
})

function printSummary () {
console.log(`Node version: ${process.versions.node}\tElectron version: ${process.versions.electron}`)
console.log(`IPC timers? ${global.timersFix ? 'yes' : 'no'}`)

;[.1, 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 98, 99, 99.5, 99.7, 100].forEach((p) => {
const q = percentile(p, differences)

console.log(`${p}%\t of setTimeout calls finished with less than ${q}ms\t of difference`)
})
}

0 comments on commit 368ead8

Please sign in to comment.