-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix flaky test issue with export tests #2080
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,211 +99,6 @@ describe('System export', () => { | |
expect(JSON.parse(resourceJSON[0])?.subject?.reference).toEqual(`Patient/${res1.body.id}`); | ||
}); | ||
|
||
test('Parameters', async () => { | ||
const { project } = await createTestProject(); | ||
expect(project).toBeDefined(); | ||
|
||
const accessToken = await initTestAuth(); | ||
expect(accessToken).toBeDefined(); | ||
|
||
const res1 = await request(app) | ||
.post(`/fhir/R4/Patient`) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.set('Content-Type', 'application/fhir+json') | ||
.send({ | ||
resourceType: 'Patient', | ||
name: [{ given: ['Alice'], family: 'Smith' }], | ||
address: [{ use: 'home', line: ['123 Main St'], city: 'Anywhere', state: 'CA', postalCode: '90210' }], | ||
telecom: [ | ||
{ system: 'phone', value: '555-555-5555' }, | ||
{ system: 'email', value: 'alice@example.com' }, | ||
], | ||
}); | ||
expect(res1.status).toBe(201); | ||
|
||
// Create observation | ||
const res2 = await request(app) | ||
.post(`/fhir/R4/Observation`) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.set('Content-Type', 'application/fhir+json') | ||
.send({ | ||
resourceType: 'Observation', | ||
status: 'final', | ||
code: { text: 'test' }, | ||
subject: { reference: `Patient/${res1.body.id}` }, | ||
}); | ||
expect(res2.status).toBe(201); | ||
|
||
await waitFor(async () => { | ||
// Create later observation | ||
const res3 = await request(app) | ||
.post(`/fhir/R4/Observation`) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.set('Content-Type', 'application/fhir+json') | ||
.send({ | ||
resourceType: 'Observation', | ||
status: 'final', | ||
code: { text: 'test2' }, | ||
subject: { reference: `Patient/${res1.body.id}` }, | ||
}); | ||
expect(res3.status).toBe(201); | ||
}); | ||
const updatedDate = new Date(res2.body.meta.lastUpdated); | ||
updatedDate.setMilliseconds(updatedDate.getMilliseconds() + 1); | ||
|
||
// Start the export | ||
let initRes: any; | ||
await waitFor(async () => { | ||
initRes = await request(app) | ||
.post('/fhir/R4/$export') | ||
.query({ | ||
_type: 'Observation', | ||
_since: updatedDate.toISOString(), | ||
}) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.set('Content-Type', 'application/fhir+json') | ||
.set('X-Medplum', 'extended') | ||
.send({}); | ||
expect(initRes.status).toBe(202); | ||
expect(initRes.headers['content-location']).toBeDefined(); | ||
}); | ||
|
||
// Check the export status | ||
const contentLocation = new URL(initRes?.headers?.['content-location']); | ||
|
||
let resBody: any; | ||
await waitFor(async () => { | ||
const statusRes = await request(app) | ||
.get(contentLocation.pathname) | ||
.set('Authorization', 'Bearer ' + accessToken); | ||
expect(statusRes.status).toBe(200); | ||
resBody = statusRes.body; | ||
}); | ||
|
||
const output = resBody?.output as BulkDataExportOutput[]; | ||
expect(Object.values(output).map((ex) => ex.type)).toEqual(['Observation']); | ||
|
||
// Get the export content | ||
const outputLocation = new URL(output[0]?.url as string); | ||
const dataRes = await request(app) | ||
.get(outputLocation.pathname + outputLocation.search) | ||
.set('Authorization', 'Bearer ' + accessToken); | ||
expect(dataRes.status).toBe(200); | ||
|
||
// Output format is "ndjson", new line delimited JSON | ||
// However, we only expect one Observation, so we can parse it as JSON | ||
const resourceJSON = dataRes.text.trim().split('\n'); | ||
expect(resourceJSON).toHaveLength(1); | ||
expect(JSON.parse(resourceJSON[0])?.code?.text).toEqual('test2'); | ||
}); | ||
|
||
test('Multiple Resources by Resource Type', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test coverage is redundant, there was a later test below that provided the same coverage. Deleting the test since it was also flaky before #2022 . https://github.com/medplum/medplum/pull/2080/files#diff-454070ab471e4a54926cd48d6d4e8e030e3158b06f16797fd9774ed037d467e9L307 |
||
const { project } = await createTestProject(); | ||
expect(project).toBeDefined(); | ||
|
||
const accessToken = await initTestAuth(); | ||
expect(accessToken).toBeDefined(); | ||
const res1 = await request(app) | ||
.post(`/fhir/R4/Patient`) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.set('Content-Type', 'application/fhir+json') | ||
.send({ | ||
resourceType: 'Patient', | ||
name: [{ given: ['Alice'], family: 'Smith' }], | ||
address: [{ use: 'home', line: ['123 Main St'], city: 'Anywhere', state: 'CA', postalCode: '90210' }], | ||
telecom: [ | ||
{ system: 'phone', value: '555-555-5555' }, | ||
{ system: 'email', value: 'alice@example.com' }, | ||
], | ||
}); | ||
expect(res1.status).toBe(201); | ||
await waitFor(async () => { | ||
// Create observation | ||
const res2 = await request(app) | ||
.post(`/fhir/R4/Observation`) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.set('Content-Type', 'application/fhir+json') | ||
.send({ | ||
resourceType: 'Observation', | ||
status: 'final', | ||
code: { text: 'test' }, | ||
subject: { reference: `Patient/${res1.body.id}` }, | ||
}); | ||
expect(res2.status).toBe(201); | ||
|
||
// Create 2nd observation | ||
const res3 = await request(app) | ||
.post(`/fhir/R4/Observation`) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.set('Content-Type', 'application/fhir+json') | ||
.send({ | ||
resourceType: 'Observation', | ||
status: 'final', | ||
code: { text: 'test2' }, | ||
subject: { reference: `Patient/${res1.body.id}` }, | ||
}); | ||
expect(res3.status).toBe(201); | ||
|
||
// Create third observation | ||
const res4 = await request(app) | ||
.post(`/fhir/R4/Observation`) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.set('Content-Type', 'application/fhir+json') | ||
.send({ | ||
resourceType: 'Observation', | ||
status: 'final', | ||
code: { text: 'test3' }, | ||
subject: { reference: `Patient/${res1.body.id}` }, | ||
}); | ||
expect(res4.status).toBe(201); | ||
}); | ||
const updatedDate = new Date(res1.body.meta.lastUpdated); | ||
updatedDate.setMilliseconds(updatedDate.getMilliseconds() - 100); | ||
|
||
// Start the export | ||
let initRes: any; | ||
await waitFor(async () => { | ||
initRes = await request(app) | ||
.post('/fhir/R4/$export') | ||
.query({ | ||
_type: 'Observation', | ||
}) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.set('Content-Type', 'application/fhir+json') | ||
.set('X-Medplum', 'extended') | ||
.send({}); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests using
_since
parameter is redundant and doesn't provide additional test coverage.since
parameter is also tested inmedplum/packages/server/src/fhir/operations/groupexport.test.ts
Line 128 in e8bff43