#scenarios not getting cleaned up (using postgres)

1 messages · Page 1 of 1 (latest)

full vapor
#

My autogenerated (scaffold) tests are failing on uniqueness constraints when they try to set up a scenario.

When I examine the test database after a test run, the DB rows from several different scenarios are still present in the database.

Any ideas on what I should be looking at to troubleshoot this?

example error:
(Background: in this case, the scenario should only create one "planting" but the "plantings" table has a uniqueness constraint so we can't have multiple copies of the scenario in the DB at once)

  ● plantings › deletes a planting

    PrismaClientKnownRequestError: 
    Invalid `getProjectDb()[model].create()` invocation in
    /home/jason/code/farm-data/node_modules/@redwoodjs/testing/config/jest/api/jest.setup.js:197:64

      194     createArgs(scenarios)
      195   )
      196 } else {
    → 197   scenarios[model][name] = await getProjectDb()[model].create(
    Unique constraint failed on the fields: (`name`,`purpose`,`seasonality`)

      at ai.handleRequestError (node_modules/@prisma/client/runtime/library.js:126:6775)
      at ai.handleAndLogRequestError (node_modules/@prisma/client/runtime/library.js:126:6109)
      at ai.request (node_modules/@prisma/client/runtime/library.js:126:5817)
      at l (node_modules/@prisma/client/runtime/library.js:131:9709)
      at seedScenario (node_modules/@redwoodjs/testing/config/jest/api/jest.setup.js:197:36)
      at Object.<anonymous> (node_modules/@redwoodjs/testing/config/jest/api/jest.setup.js:106:28)

Test Suites: 1 failed, 1 total
Tests:       5 failed, 5 total
Snapshots:   0 total
Time:        0.706 s, estimated 1 s
#

here's another example failure, on an autogenerated test for my pretty simple User model:

 FAIL  api/src/services/users/users.test.ts
  ● users › returns all users

    expect(received).toEqual(expected) // deep equality

    Expected: 2
    Received: 4

      14 |     const result = await users()
      15 |
    > 16 |     expect(result.length).toEqual(Object.keys(scenario.user).length)
         |                           ^
      17 |   })
      18 |
      19 |   scenario('returns a single user', async (scenario: StandardScenario) => {

      at toEqual (api/src/services/users/users.test.ts:16:27)
      at Object.<anonymous> (node_modules/@redwoodjs/testing/config/jest/api/jest.setup.js:107:22)
#

Things I've tried:

  • disabling Prisma connection pooling by adding "?connection_limit=1" to the end of the connection string. Oddly only the params applied to the DATABASE_URL, not the TEST_DATABASE_URL, changed the logged pool size. Different bug?
  • disabling multiprocessing in Jest (yarn yest -w 1)

I'm thinking that even with multiprocessing disabled and connections limited, there's still some parallelism going on in the tests. If I run fewer tests (like, just one file), then the error does not occur.

sour bobcat
#

I feel like I’ve run across some documentation about this. Lemme see if I can recall. Otherwise, this might be a gos one for the forums.