-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Unskip search api tests #123145
Merged
Dosant
merged 4 commits into
elastic:main
from
Dosant:d/2022-01-17-unskip-search-api-tests
Jan 19, 2022
Merged
Unskip search api tests #123145
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,17 +6,53 @@ | |
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import type { Context } from 'mocha'; | ||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
import { verifyErrorResponse } from '../../../../../test/api_integration/apis/search/verify_error'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
const esArchiver = getService('esArchiver'); | ||
const es = getService('es'); | ||
const log = getService('log'); | ||
const retry = getService('retry'); | ||
|
||
const shardDelayAgg = (delay: string) => ({ | ||
aggs: { | ||
delay: { | ||
shard_delay: { | ||
value: delay, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
async function markRequiresShardDelayAgg(testContext: Context) { | ||
const body = await es.info(); | ||
if (!body.version.number.includes('SNAPSHOT')) { | ||
log.debug('Skipping because this build does not have the required shard_delay agg'); | ||
testContext.skip(); | ||
} | ||
} | ||
|
||
describe('search', () => { | ||
// https://github.com/elastic/kibana/issues/113082 | ||
describe.skip('post', () => { | ||
it('should return 200 with final response if wait_for_completion_timeout is long enough', async () => { | ||
before(async () => { | ||
// ensure es not empty | ||
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. I found that |
||
await es.index({ | ||
index: 'search-api-test', | ||
id: 'search-api-test-doc', | ||
body: { message: 'test doc' }, | ||
refresh: 'wait_for', | ||
}); | ||
}); | ||
after(async () => { | ||
await es.indices.delete({ | ||
index: 'search-api-test', | ||
}); | ||
}); | ||
|
||
describe('post', () => { | ||
it('should return 200 with final response without search id if wait_for_completion_timeout is long enough', async function () { | ||
const resp = await supertest | ||
.post(`/internal/search/ese`) | ||
.set('kbn-xsrf', 'foo') | ||
|
@@ -27,7 +63,7 @@ export default function ({ getService }: FtrProviderContext) { | |
match_all: {}, | ||
}, | ||
}, | ||
wait_for_completion_timeout: '1000s', | ||
wait_for_completion_timeout: '10s', | ||
}, | ||
}) | ||
.expect(200); | ||
|
@@ -39,7 +75,9 @@ export default function ({ getService }: FtrProviderContext) { | |
expect(resp.body).to.have.property('rawResponse'); | ||
}); | ||
|
||
it('should return 200 with partial response if wait_for_completion_timeout is not long enough', async () => { | ||
it('should return 200 with search id and partial response if wait_for_completion_timeout is not long enough', async function () { | ||
await markRequiresShardDelayAgg(this); | ||
|
||
const resp = await supertest | ||
.post(`/internal/search/ese`) | ||
.set('kbn-xsrf', 'foo') | ||
|
@@ -49,6 +87,7 @@ export default function ({ getService }: FtrProviderContext) { | |
query: { | ||
match_all: {}, | ||
}, | ||
...shardDelayAgg('3s'), | ||
}, | ||
wait_for_completion_timeout: '1ms', | ||
}, | ||
|
@@ -62,7 +101,9 @@ export default function ({ getService }: FtrProviderContext) { | |
expect(resp.body).to.have.property('rawResponse'); | ||
}); | ||
|
||
it('should retrieve results with id', async () => { | ||
it('should retrieve results from completed search with search id', async function () { | ||
await markRequiresShardDelayAgg(this); | ||
|
||
const resp = await supertest | ||
.post(`/internal/search/ese`) | ||
.set('kbn-xsrf', 'foo') | ||
|
@@ -72,15 +113,58 @@ export default function ({ getService }: FtrProviderContext) { | |
query: { | ||
match_all: {}, | ||
}, | ||
...shardDelayAgg('3s'), | ||
}, | ||
wait_for_completion_timeout: '1ms', | ||
}, | ||
}) | ||
.expect(200); | ||
|
||
const { id } = resp.body; | ||
expect(id).not.to.be(undefined); | ||
expect(resp.body.isPartial).to.be(true); | ||
expect(resp.body.isRunning).to.be(true); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 3000)); | ||
|
||
await retry.tryForTime(10000, async () => { | ||
const resp2 = await supertest | ||
.post(`/internal/search/ese/${id}`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({}) | ||
.expect(200); | ||
|
||
expect(resp2.body.id).not.to.be(undefined); | ||
expect(resp2.body.isPartial).to.be(false); | ||
expect(resp2.body.isRunning).to.be(false); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 2000)); | ||
return true; | ||
}); | ||
}); | ||
|
||
it('should retrieve results from in-progress search with search id', async function () { | ||
await markRequiresShardDelayAgg(this); | ||
|
||
const resp = await supertest | ||
.post(`/internal/search/ese`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({ | ||
params: { | ||
body: { | ||
query: { | ||
match_all: {}, | ||
}, | ||
...shardDelayAgg('10s'), | ||
}, | ||
wait_for_completion_timeout: '1ms', | ||
}, | ||
}) | ||
.expect(200); | ||
|
||
const { id } = resp.body; | ||
expect(id).not.to.be(undefined); | ||
expect(resp.body.isPartial).to.be(true); | ||
expect(resp.body.isRunning).to.be(true); | ||
|
||
const resp2 = await supertest | ||
.post(`/internal/search/ese/${id}`) | ||
|
@@ -89,8 +173,8 @@ export default function ({ getService }: FtrProviderContext) { | |
.expect(200); | ||
|
||
expect(resp2.body.id).not.to.be(undefined); | ||
expect(resp2.body.isPartial).to.be(false); | ||
expect(resp2.body.isRunning).to.be(false); | ||
expect(resp2.body.isPartial).to.be(true); | ||
expect(resp2.body.isRunning).to.be(true); | ||
}); | ||
|
||
it('should fail without kbn-xref header', async () => { | ||
|
@@ -147,7 +231,7 @@ export default function ({ getService }: FtrProviderContext) { | |
verifyErrorResponse(resp.body, 400, 'illegal_argument_exception', true); | ||
}); | ||
|
||
it('should return 404 if unkown id is provided', async () => { | ||
it('should return 404 if unknown id is provided', async () => { | ||
const resp = await supertest | ||
.post( | ||
`/internal/search/ese/FkxOb21iV1g2VGR1S2QzaWVtRU9fMVEbc3JWeWc1VHlUdDZ6MENxcXlYVG1Fdzo2NDg4` | ||
|
@@ -250,8 +334,7 @@ export default function ({ getService }: FtrProviderContext) { | |
}); | ||
}); | ||
|
||
// FLAKY: https://github.com/elastic/kibana/issues/119272 | ||
describe.skip('delete', () => { | ||
describe('delete', () => { | ||
it('should return 404 when no search id provided', async () => { | ||
await supertest.delete(`/internal/search/ese`).set('kbn-xsrf', 'foo').send().expect(404); | ||
}); | ||
|
@@ -265,7 +348,47 @@ export default function ({ getService }: FtrProviderContext) { | |
verifyErrorResponse(resp.body, 400, 'illegal_argument_exception', true); | ||
}); | ||
|
||
it('should delete a search', async () => { | ||
it('should delete an in-progress search', async function () { | ||
await markRequiresShardDelayAgg(this); | ||
|
||
const resp = await supertest | ||
.post(`/internal/search/ese`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({ | ||
params: { | ||
body: { | ||
query: { | ||
match_all: {}, | ||
}, | ||
...shardDelayAgg('10s'), | ||
}, | ||
wait_for_completion_timeout: '1ms', | ||
}, | ||
}) | ||
.expect(200); | ||
|
||
const { id } = resp.body; | ||
expect(id).not.to.be(undefined); | ||
expect(resp.body.isPartial).to.be(true); | ||
expect(resp.body.isRunning).to.be(true); | ||
|
||
await supertest | ||
.delete(`/internal/search/ese/${id}`) | ||
.set('kbn-xsrf', 'foo') | ||
.send() | ||
.expect(200); | ||
|
||
// try to re-fetch | ||
await supertest | ||
.post(`/internal/search/ese/${id}`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({}) | ||
.expect(404); | ||
}); | ||
|
||
it('should delete a completed search', async function () { | ||
await markRequiresShardDelayAgg(this); | ||
|
||
const resp = await supertest | ||
.post(`/internal/search/ese`) | ||
.set('kbn-xsrf', 'foo') | ||
|
@@ -275,13 +398,34 @@ export default function ({ getService }: FtrProviderContext) { | |
query: { | ||
match_all: {}, | ||
}, | ||
...shardDelayAgg('3s'), | ||
}, | ||
wait_for_completion_timeout: '1ms', | ||
}, | ||
}) | ||
.expect(200); | ||
|
||
const { id } = resp.body; | ||
expect(id).not.to.be(undefined); | ||
expect(resp.body.isPartial).to.be(true); | ||
expect(resp.body.isRunning).to.be(true); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 3000)); | ||
|
||
await retry.tryForTime(10000, async () => { | ||
const resp2 = await supertest | ||
.post(`/internal/search/ese/${id}`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({}) | ||
.expect(200); | ||
|
||
expect(resp2.body.id).not.to.be(undefined); | ||
expect(resp2.body.isPartial).to.be(false); | ||
expect(resp2.body.isRunning).to.be(false); | ||
|
||
return true; | ||
}); | ||
|
||
await supertest | ||
.delete(`/internal/search/ese/${id}`) | ||
.set('kbn-xsrf', 'foo') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using dev only shard_delay agg to stabilize checks the depend on how much time it took to get the result