matrix-org / matrix-org/matrix-js-sdk
'STOPPED' event emitted to early, console.logs are still pending
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.2k
- Forks
- 704
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 40
Description
Hi,
within my tests that run successfully, I observed once I call stopClient() on the matrixClient, the emitted 'STOPPED' event was triggered to early, because there were still pending console.logs for event state transitions, even though all message events got emitted correctly:
` ● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Event sent to !gHPFtGfEHaQnEhncvm:matrix.org with event id $pqzhHixoHQJNi-zi3vvem0Glm2zBV2vglrKCQAV2Hz8".
at CustomConsole.log (node_modules/@jest/console/build/CustomConsole.js:183:10)
at node_modules/matrix-js-sdk/src/client.js:2055:16
at tryCatcher (node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (node_modules/bluebird/js/release/promise.js:517:31)
at Promise._settlePromise (node_modules/bluebird/js/release/promise.js:574:18)
at Promise._fulfillPromises (node_modules/bluebird/js/release/promise.js:674:14)
at Promise._settlePromises (node_modules/bluebird/js/release/promise.js:700:18)
at _drainQueueStep (node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (node_modules/bluebird/js/release/async.js:131:9)
at Async.Object.<anonymous>.Async._drainQueues (node_modules/bluebird/js/release/async.js:147:5)
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "setting pendingEvent status to sent in !gHPFtGfEHaQnEhncvm:matrix.org".
at CustomConsole.log (node_modules/@jest/console/build/CustomConsole.js:183:10)
at Room.updatePendingEvent (node_modules/matrix-js-sdk/src/models/room.js:1316:12)
at node_modules/matrix-js-sdk/src/client.js:1919:18
at tryCatcher (node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (node_modules/bluebird/js/release/promise.js:517:31)
at Promise._settlePromise (node_modules/bluebird/js/release/promise.js:574:18)
at Promise._settlePromise0 (node_modules/bluebird/js/release/promise.js:619:10)
at Promise._settlePromises (node_modules/bluebird/js/release/promise.js:699:18)
at _drainQueueStep (node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (node_modules/bluebird/js/release/async.js:131:9)
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "setting pendingEvent status to sending in !gHPFtGfEHaQnEhncvm:matrix.org".
at CustomConsole.log (node_modules/@jest/console/build/CustomConsole.js:183:10)
at Room.updatePendingEvent (node_modules/matrix-js-sdk/src/models/room.js:1316:12)
at _updatePendingEventStatus (node_modules/matrix-js-sdk/src/client.js:2017:14)
at MatrixScheduler._procFn (node_modules/matrix-js-sdk/src/client.js:204:17)
at node_modules/matrix-js-sdk/src/scheduler.js:230:26
at tryCatcher (node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (node_modules/bluebird/js/release/promise.js:517:31)
at Promise._settlePromise (node_modules/bluebird/js/release/promise.js:574:18)
at Promise._settlePromiseCtx (node_modules/bluebird/js/release/promise.js:611:10)
at _drainQueueStep (node_modules/bluebird/js/release/async.js:142:12)
`
Within my jest tests I wait for this emitted STOPPED event to invoke the done method.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/client.js around stopClient(), the STOPPED event, and the pending-event handling shown in the stack traces; also inspect src/models/room.js and src/scheduler.js. Reproduce the Jest test that waits for STOPPED and verify that pending event-state updates finish before the event, with no logs occurring after the test completes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100