Fix tests
This commit is contained in:
parent
888820a0de
commit
252c23f8bd
|
@ -10,18 +10,24 @@ import {
|
||||||
init,
|
init,
|
||||||
} from "../docWritethrough"
|
} from "../docWritethrough"
|
||||||
|
|
||||||
import InMemoryQueue from "../../queue/inMemoryQueue"
|
|
||||||
|
|
||||||
const initialTime = Date.now()
|
const initialTime = Date.now()
|
||||||
|
|
||||||
async function waitForQueueCompletion() {
|
async function waitForQueueCompletion() {
|
||||||
const queue: InMemoryQueue = DocWritethroughProcessor.queue as never
|
await DocWritethroughProcessor.queue.resume()
|
||||||
await queue.waitForCompletion()
|
do {
|
||||||
|
await DocWritethroughProcessor.queue.whenCurrentJobsFinished()
|
||||||
|
} while (await DocWritethroughProcessor.queue.count())
|
||||||
|
|
||||||
|
await DocWritethroughProcessor.queue.whenCurrentJobsFinished()
|
||||||
|
|
||||||
|
await DocWritethroughProcessor.queue.pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("docWritethrough", () => {
|
describe("docWritethrough", () => {
|
||||||
beforeAll(() => {
|
beforeAll(async () => {
|
||||||
init()
|
init()
|
||||||
|
await DocWritethroughProcessor.queue.isReady()
|
||||||
|
await DocWritethroughProcessor.queue.pause()
|
||||||
})
|
})
|
||||||
|
|
||||||
const config = new DBTestConfiguration()
|
const config = new DBTestConfiguration()
|
||||||
|
@ -67,7 +73,7 @@ describe("docWritethrough", () => {
|
||||||
const patch3 = generatePatchObject(3)
|
const patch3 = generatePatchObject(3)
|
||||||
await docWritethrough.patch(patch3)
|
await docWritethrough.patch(patch3)
|
||||||
|
|
||||||
expect(await db.get(documentId)).toEqual({
|
expect(await db.tryGet(documentId)).toEqual({
|
||||||
_id: documentId,
|
_id: documentId,
|
||||||
...patch1,
|
...patch1,
|
||||||
...patch2,
|
...patch2,
|
||||||
|
@ -92,7 +98,7 @@ describe("docWritethrough", () => {
|
||||||
|
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
|
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
_id: documentId,
|
_id: documentId,
|
||||||
...patch1,
|
...patch1,
|
||||||
|
@ -117,7 +123,7 @@ describe("docWritethrough", () => {
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
|
|
||||||
expect(date1).not.toEqual(date2)
|
expect(date1).not.toEqual(date2)
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
createdAt: date1.toISOString(),
|
createdAt: date1.toISOString(),
|
||||||
updatedAt: date2.toISOString(),
|
updatedAt: date2.toISOString(),
|
||||||
|
@ -135,7 +141,7 @@ describe("docWritethrough", () => {
|
||||||
await docWritethrough.patch(patch2)
|
await docWritethrough.patch(patch2)
|
||||||
|
|
||||||
const keyToOverride = _.sample(Object.keys(patch1))!
|
const keyToOverride = _.sample(Object.keys(patch1))!
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
[keyToOverride]: patch1[keyToOverride],
|
[keyToOverride]: patch1[keyToOverride],
|
||||||
})
|
})
|
||||||
|
@ -150,7 +156,7 @@ describe("docWritethrough", () => {
|
||||||
await docWritethrough.patch(patch3)
|
await docWritethrough.patch(patch3)
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
|
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
...patch1,
|
...patch1,
|
||||||
...patch2,
|
...patch2,
|
||||||
|
@ -180,14 +186,14 @@ describe("docWritethrough", () => {
|
||||||
await secondDocWritethrough.patch(doc2Patch2)
|
await secondDocWritethrough.patch(doc2Patch2)
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
|
|
||||||
expect(await db.get(docWritethrough.docId)).toEqual(
|
expect(await db.tryGet(docWritethrough.docId)).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
...doc1Patch,
|
...doc1Patch,
|
||||||
...doc1Patch2,
|
...doc1Patch2,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(await db.get(secondDocWritethrough.docId)).toEqual(
|
expect(await db.tryGet(secondDocWritethrough.docId)).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
...doc2Patch,
|
...doc2Patch,
|
||||||
...doc2Patch2,
|
...doc2Patch2,
|
||||||
|
@ -203,7 +209,7 @@ describe("docWritethrough", () => {
|
||||||
await docWritethrough.patch(initialPatch)
|
await docWritethrough.patch(initialPatch)
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
|
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining(initialPatch)
|
expect.objectContaining(initialPatch)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -214,10 +220,10 @@ describe("docWritethrough", () => {
|
||||||
await docWritethrough.patch(extraPatch)
|
await docWritethrough.patch(extraPatch)
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
|
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining(extraPatch)
|
expect.objectContaining(extraPatch)
|
||||||
)
|
)
|
||||||
expect(await db.get(documentId)).not.toEqual(
|
expect(await db.tryGet(documentId)).not.toEqual(
|
||||||
expect.objectContaining(initialPatch)
|
expect.objectContaining(initialPatch)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -242,7 +248,7 @@ describe("docWritethrough", () => {
|
||||||
expect(queueMessageSpy).toHaveBeenCalledTimes(5)
|
expect(queueMessageSpy).toHaveBeenCalledTimes(5)
|
||||||
|
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining(patches)
|
expect.objectContaining(patches)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -250,7 +256,7 @@ describe("docWritethrough", () => {
|
||||||
expect(queueMessageSpy).toHaveBeenCalledTimes(45)
|
expect(queueMessageSpy).toHaveBeenCalledTimes(45)
|
||||||
|
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining(patches)
|
expect.objectContaining(patches)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -258,7 +264,7 @@ describe("docWritethrough", () => {
|
||||||
expect(queueMessageSpy).toHaveBeenCalledTimes(55)
|
expect(queueMessageSpy).toHaveBeenCalledTimes(55)
|
||||||
|
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining(patches)
|
expect.objectContaining(patches)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -279,13 +285,13 @@ describe("docWritethrough", () => {
|
||||||
await incrementalPatches(5)
|
await incrementalPatches(5)
|
||||||
|
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining({ [keyToOverride]: 5 })
|
expect.objectContaining({ [keyToOverride]: 5 })
|
||||||
)
|
)
|
||||||
|
|
||||||
await incrementalPatches(40)
|
await incrementalPatches(40)
|
||||||
await waitForQueueCompletion()
|
await waitForQueueCompletion()
|
||||||
expect(await db.get(documentId)).toEqual(
|
expect(await db.tryGet(documentId)).toEqual(
|
||||||
expect.objectContaining({ [keyToOverride]: 45 })
|
expect.objectContaining({ [keyToOverride]: 45 })
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue