Skip to content

investigate uptick in failing integration tests on Travis/Appveyor #6793

Closed

Description

@shiftkey

Opening this up to brain dump so it's not just in my head

Travis CI:

AppVeyor:

Other infrastructure: unclear

Problem behaviour:

  • jest runs to execute launch test
  • spectron initializes using build application bundle
  • test fails because of a timeout to launch the app
$ cross-env TEST_ENV=1 ELECTRON_NO_ATTACH_CONSOLE=1 xvfb-maybe --auto-servernum -- jest --config ./app/jest.integration.config.js
FAIL app/test/integration/launch-test.ts (12.399s)
  App
    ✕ opens a window on launch (10008ms)
  ● App › opens a window on launch
    Timeout - Async callback was not invoked within the 10000ms timeout specified by jest.setTimeout.
      at mapper (../node_modules/jest-jasmine2/build/queue_runner.js:41:52)
  ● App › opens a window on launch
    TypeError: Cannot read property 'isVisible' of undefined
      40 | 
      41 |   it('opens a window on launch', async () => {
    > 42 |     await app.client.waitUntil(() => app.browserWindow.isVisible(), 5000)
         |                                                        ^
      43 | 
      44 |     const count = await app.client.getWindowCount()
      45 |     expect(count).toBe(1)
      at Object.app.client.waitUntil (test/integration/launch-test.ts:42:56)
      at Timer.tick (../node_modules/webdriverio/build/lib/utils/Timer.js:111:31)
      at Timer.start (../node_modules/webdriverio/build/lib/utils/Timer.js:75:22)
      at new Timer (../node_modules/webdriverio/build/lib/utils/Timer.js:62:14)
      at Object.<anonymous>.exports.default (../node_modules/webdriverio/build/lib/commands/waitUntil.js:25:17)
      at Object.exec (../node_modules/webdriverio/build/lib/helpers/safeExecute.js:28:24)
      at Object.resolve (../node_modules/webdriverio/build/lib/webdriverio.js:190:29)
      at lastPromise.then.resolve.call.depth (../node_modules/webdriverio/build/lib/webdriverio.js:485:32)
      at _fulfilled (../node_modules/q/q.js:854:54)
      at self.promiseDispatch.done (../node_modules/q/q.js:883:30)
      at Promise.promise.promiseDispatch (../node_modules/q/q.js:816:13)
      at ../node_modules/q/q.js:570:49
      at runSingle (../node_modules/q/q.js:137:13)
      at flush (../node_modules/q/q.js:125:13)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        12.976s
Ran all test suites.
  • jest does not terminate
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
  • CI is aborted because of inactivity
No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received
The build has been terminated

Root cause ideas:

  • Electron 2/3 upgrades? Downgrades between major versions are not recommended, but we've been testing Electron 3 to get ready for next release. Maybe build agent is trying to launch a v2 app against a v3 data directory?
  • Build agent unexpected caching files between builds
  • Spectron upgrade too early and uncovered some sort of v2-specific issue? downgrade does not seem to fix this issue
  • using jest to drive end-to-end tests and in this case it seems to deadlock ignoring for now
  • ???

TODO:

Activity

  1. added
    infrastructure
    on Feb 7, 2019
  2. self-assigned this
    on Feb 7, 2019
  3. changed the title [-]investigate uptick in failing integration tests on Travis[/-] [+]investigate uptick in failing integration tests on Travis/Appveyor[/+] on Feb 7, 2019
  4. shiftkey commented on Feb 8, 2019

    @shiftkey
    MemberAuthor

    So after rewriting the test to something I can interrogate better when running on another server, I was able to grab a ChromeDriver log file that shows, after it does some setup of the test environment, it gets stuck trying to reach this endpoint every 50ms until the 30s timeout kicks in:

    [10.504][DEBUG]: DevTools request: http://localhost:12784/json/version
    [10.504][DEBUG]: DevTools request failed
    

    And this vague error:

    [0.538][DEBUG]: DevTools request failed
    _stream_readable.js:595
        dest.end();
             ^
    TypeError: dest.end is not a function
        at Socket.onend (_stream_readable.js:595:10)
        at Object.onceWrapper (events.js:313:30)
        at emitNone (events.js:111:20)
        at Socket.emit (events.js:208:7)
        at endReadableNT (_stream_readable.js:1064:12)
        at _combinedTickCallback (internal/process/next_tick.js:139:11)
        at process._tickCallback (internal/process/next_tick.js:181:9)
    

    I have a theory that something is persisting within these problem builds as part of downgrading from Electron 3 to Electron 2, but things in %APPDATA% (on Windows) or ~/.config (on Linux) really shouldn't persist between builds, so I'm not sure what other state could be involved here.

  5. shiftkey commented on Feb 8, 2019

    @shiftkey
    MemberAuthor

    Another interesting data point: I wanted to see what version of Electron is found inside node_modules/electron/dist/electron[.exe]. This is the code that should do the trick:

    function checkElectronVersion() {
      const electronDir = path.join(root, 'node_modules', 'electron', 'dist')
      const command =
        process.platform === 'win32'
          ? 'electron.exe --version'
          : 'electron --version'
      const output = execSync(command, { cwd: electronDir })
      const text = output.toString('utf8')
      console.log(`electron output: ${text}`)
    }

    And output something like this:

    electron output: v2.0.13
    

    But on Travis I see that my execSync fails because it can't find something that electron depends on:

    module.js:545
        throw err;
        ^
    Error: Cannot find module '/home/travis/build/desktop/desktop/node_modules/electron/dist/resources/electron.asar/browser/init.js'
        at Function.Module._resolveFilename (module.js:543:15)
        at Function.Module._load (module.js:473:25)
        at Function.Module.runMain (module.js:683:10)
        at startup (bootstrap_node.js:196:16)
        at bootstrap_node.js:622:3
    Error: Command failed: electron --version
    module.js:545
        throw err;
        ^
    Error: Cannot find module '/home/travis/build/desktop/desktop/node_modules/electron/dist/resources/electron.asar/browser/init.js'
        at Function.Module._resolveFilename (module.js:543:15)
        at Function.Module._load (module.js:473:25)
        at Function.Module.runMain (module.js:683:10)
        at startup (bootstrap_node.js:196:16)
        at bootstrap_node.js:622:3
        at checkExecSyncError (child_process.js:602:13)
        at Object.execSync (child_process.js:642:13)
        at checkElectronVersion (/home/travis/build/desktop/desktop/script/run-integration-tests.ts:88:18)
        at Object.<anonymous> (/home/travis/build/desktop/desktop/script/run-integration-tests.ts:152:1)
        at Module._compile (module.js:653:30)
        at Module.m._compile (/home/travis/build/desktop/desktop/node_modules/ts-node/src/index.ts:439:23)
        at Module._extensions..js (module.js:664:10)
        at Object.require.extensions.(anonymous function) [as .ts] (/home/travis/build/desktop/desktop/node_modules/ts-node/src/index.ts:442:12)
        at Module.load (module.js:566:32)
        at tryModuleLoad (module.js:506:12)
    

    And I can see Appveyor fail in the same way:

    user data directory is empty: 'C:\Users\appveyor\AppData\Roaming\GitHub Desktop'
    module.js:545
        throw err;
        ^
    Error: Cannot find module 'C:\projects\desktop\node_modules\electron\dist\resources\electron.asar\browser\init.js'
        at Function.Module._resolveFilename (module.js:543:15)
        at Function.Module._load (module.js:473:25)
        at Function.Module.runMain (module.js:683:10)
        at startup (bootstrap_node.js:196:16)
        at bootstrap_node.js:622:3
    Error: Command failed: electron.exe --version
    module.js:545
        throw err;
        ^
    Error: Cannot find module 'C:\projects\desktop\node_modules\electron\dist\resources\electron.asar\browser\init.js'
        at Function.Module._resolveFilename (module.js:543:15)
        at Function.Module._load (module.js:473:25)
        at Function.Module.runMain (module.js:683:10)
        at startup (bootstrap_node.js:196:16)
        at bootstrap_node.js:622:3
        at checkExecSyncError (child_process.js:602:13)
        at Object.execSync (child_process.js:642:13)
        at checkElectronVersion (C:\projects\desktop\script\run-integration-tests.ts:88:18)
        at Object.<anonymous> (C:\projects\desktop\script\run-integration-tests.ts:152:1)
        at Module._compile (module.js:653:30)
        at Module.m._compile (C:\projects\desktop\node_modules\ts-node\src\index.ts:439:23)
        at Module._extensions..js (module.js:664:10)
        at Object.require.extensions.(anonymous function) [as .ts] (C:\projects\desktop\node_modules\ts-node\src\index.ts:442:12)
        at Module.load (module.js:566:32)
        at tryModuleLoad (module.js:506:12)
    

    Why does this even matter? Because our integration tests are launching the electron CLI (and yarn creates a shim under node_modules/.bin/ so it's available on your PATH.

    https://github.com/desktop/desktop/blob/b4d5fed8a8dfd9e3edc790886ece9eb6dc0b1e88/script/run-integration-tests.ts#L58-L75

    More info about this feature here.

    So given that I don't seem to have a working electron binary to test here, I have a few options, in descending order of impact:

    1. switch the integration test over to run the packaged app, see if that changes anything
    2. remove the cached node_modules/electron before doing a yarn install and see if that affects the integration tests
    3. disable caching node_modules on all CI platforms

    The 2nd point is something I've been talking with @iAmWillShepherd about privately this week when he had to workaround what I thought was a different caching issue, but now I feel it's related to this issue:

    • We've not seen this problem on CircleCI because it fails at install time because the electron package is cached, and it can't downgrade. Turns out I already knew about this. If it was able to yarn install --force without error I believe it'd show the same issue as Travis and Appveyor.
    • Azure Pipelines doesn't support any caching, and has not reported this issue at all
  6. shiftkey commented on Feb 8, 2019

    @shiftkey
    MemberAuthor

    Some notes about how Travis and Appveyor do caching:

    • Appveyor doesn't seem to distinguish between where a build is run, and only looks at the cache item

    For every cache item AppVeyor checks if its archive exists in build cache and if it does AppVeyor downloads archive and unpack it to original location.

    Based on that description one could theorize that, when I ran a CI build that used Electron 3 it would cache that, and then serve it up for an Electron 2 CI build after. It's hard to say more, but I've added a commit to #6799 which will hint to Appveyor that node_modules should be cached based on the contents of package.json.

    Here's the cache lookup for a failing build on #6776:

    fetching PR.6776/cache-linux-trusty-3653279a7665faba8e2be1d12ef7395a6b9acffd5f3cc5a68f0565de5acd959d--node-8.12.tgz
    found cache
    

    And here's the cache lookup for a successful build on #6776:

    fetching PR.6776/cache-linux-trusty-3653279a7665faba8e2be1d12ef7395a6b9acffd5f3cc5a68f0565de5acd959d--node-8.12.tgz
    fetching PR.6776/cache--node-8.12.tgz
    fetching development/cache-linux-trusty-3653279a7665faba8e2be1d12ef7395a6b9acffd5f3cc5a68f0565de5acd959d--node-8.12.tgz
    found cache
    

    I ended up invalidating the PR cache via the Travis admin portal after I noticed the broken electron --version, so seeing the build fall back to using the default branch (still Electron 2) is what I expected to happen, and seeing it succeed makes me think this is also related to caching of node_modules for some branches.

  7. shiftkey commented on Feb 9, 2019

    @shiftkey
    MemberAuthor

    Just encountered a different error error while trying to run the unit tests:

    $ cross-env ELECTRON_RUN_AS_NODE=1 ./node_modules/.bin/electron ./node_modules/jest/bin/jest --detectOpenHandles --silent --config ./app/jest.unit.config.js --coverage --runInBand
    C:\projects\desktop\node_modules\electron\index.js:9
      throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
      ^
    Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
        at Object.<anonymous> (C:\projects\desktop\node_modules\electron\index.js:9:9)
        at Module._compile (module.js:653:30)
        at Object.Module._extensions..js (module.js:664:10)
        at Module.load (module.js:566:32)
        at tryModuleLoad (module.js:506:12)
        at Function.Module._load (module.js:498:3)
        at Module.require (module.js:597:17)
        at require (internal/module.js:11:18)
        at Object.<anonymous> (C:\projects\desktop\node_modules\electron\cli.js:3:16)
        at Module._compile (module.js:653:30)
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    Command exited with code 1
    

    This was after disabling the caching of node_modules, so it's a new thing to investigate:

    Restoring build cache
    Cache '.eslintcache' - Restored
    Cache 'C:\Users\appveyor\.electron' - Restored
    Cache 'C:\Users\appveyor\AppData\Local\Yarn' - Restored
    Running Install scripts
    
  8. shiftkey commented on Feb 14, 2019

    @shiftkey
    MemberAuthor

    Going to close this out because I think we've learned a lot about what was uncovered, and we've made some significant improvements to the CI process to prevent this from happening again:

    We'll see if these changes help out the next time things go awry, or whether we need to refine these further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

infrastructure

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions