fix: try more progress

This commit is contained in:
Nolan Lawson 2024-03-10 22:25:45 -07:00
parent fc835ac357
commit c820e67be6
2 changed files with 25 additions and 7 deletions

View File

@ -11,11 +11,8 @@ export async function checkForUpdates (db, dataSource, signal) {
}
if (!eTag) { // work around lack of ETag/Access-Control-Expose-Headers
console.info('A get etag, aborted=', signal.aborted)
const eTagAndData = await getETagAndData(dataSource)
console.info('A got etag, aborted=', signal.aborted)
if (signal.aborted) {
console.info('A returning early')
return
}
@ -38,11 +35,8 @@ export async function checkForUpdates (db, dataSource, signal) {
} else {
console.log('Database update available')
if (!emojiData) {
console.info('B get etag, aborted=', signal.aborted)
const eTagAndData = await getETagAndData(dataSource)
console.info('B got etag, aborted=', signal.aborted)
if (signal.aborted) {
console.info('B returning early')
return
}

View File

@ -31,7 +31,31 @@ describe('database timing tests', () => {
]
scenarios.forEach(({ testName, dataSource }) => {
describe(testName, () => {
new Array(10).fill().forEach((_, count) => {
let descriptor
let onSignalAbortedCalled = new EventTarget()
beforeEach(() => {
descriptor = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')
Object.defineProperty(AbortSignal.prototype, 'aborted', {
get() {
console.info('signal dot aborted called')
onSignalAbortedCalled.dispatchEvent(new CustomEvent('signal-dot-aborted'))
return descriptor.get.apply(this)
},
set(val) {
return descriptor.set.apply(this, val)
}
})
})
afterEach(() => {
Object.defineProperty(AbortSignal.prototype, 'aborted', descriptor)
})
// Number of times somebody called the getter on `signal.aborted` which
// we are using as an easy way to get full code coverage here
const signalAbortedCheckCounts = new Array(5).fill().map((_, i) => i)
signalAbortedCheckCounts.forEach(count => {
test(`throws no errors when DB is canceled after ${count} ticks`, async () => {
// first load
const db = new Database({ dataSource })