sfbrigade / bats-server

Routed is an app to help ambulances direct non-critical patients to hospital emergency rooms with the most availability.
https://routedapp.org/
GNU Affero General Public License v3.0
18 stars 12 forks source link

Ringdown `creates a new ambulance record as needed` test is failing #156

Closed fwextensions closed 2 years ago

fwextensions commented 2 years ago

When executing npm run test:server, the test ends with this output:

  /api/ringdowns
    GET /
      ✓ returns a list of all ringdowns (65ms)
      ✓ returns a list of all ringdowns filtered by hospital (64ms)
      ✓ returns a list of active ringdowns created by the calling EMS user (66ms)
    POST /
      ✓ creates a ringdown (70ms)
      1) "before each" hook for "creates a new ambulance record as needed"

  9 passing (2s)
  1 failing

  1) "before each" hook for "creates a new ambulance record as needed":
     SequelizeForeignKeyConstraintError: update or delete on table "ambulance" violates foreign key constraint "patientdelivery_ambulance_fk" on table "patientdelivery"
      at Query.formatError (node_modules/sequelize/lib/dialects/postgres/query.js:315:16)
      at Query.run (node_modules/sequelize/lib/dialects/postgres/query.js:87:18)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async /opt/node/app/node_modules/sequelize/lib/sequelize.js:619:16
      at async resetDatabase (test/helper.js:18:3)
      at async Context.<anonymous> (test/helper.js:34:3)

The test stops after that, so it's possible there are other failing tests. I'm not familiar enough with Mocha to know how to force it to keep going. (From the docs, it seems like it should by default.)

francisli commented 2 years ago

Hmm, it looks like we may have a non-deterministic error failure... on the main sfbrigade repo we run the test suite with Github checks so everything should be passing...

I often find that these issues are related to the prior test API returning responses within a transaction. The test runner gets the response, and then goes to the next test before the transaction commits, and we get some weird out-of-order serialization of the prior test transaction and the setup for the next test.

Will need to investigate further to see if I can reproduce...

fwextensions commented 2 years ago

Running just the ringdown tests with mocha --recursive --grep "/api/ringdowns POST" seems to work.

  /api/ringdowns
    POST /
      ✓ creates a ringdown (104ms)
      ✓ creates a new ambulance record as needed (72ms)

  2 passing (666ms)

I'm not sure why the test stops when it hits that one failing test. If just those are skipped with mocha --recursive --grep "/api/ringdowns POST" --invert, more tests run, but it still stops with a failure:

  36 passing (5s)
  1 failing

  1) /api/ringdowns
       PATCH /:id
         updates an existing ringdown:
     AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:

null !== 99

      at Context.<anonymous> (test/integration/api/ringdowns.js:369:14)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)