mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[es/ensureTypesExist] ensure that random types are unique (#25601)
Fixes https://github.com/elastic/kibana/issues/22404 When `chance.word()` returns the same word twice in a set it would cause the failure seen in this issue, ensuring that unique words are always picked should prevent it.
This commit is contained in:
parent
8ff8715fee
commit
30a7cefd39
1 changed files with 13 additions and 1 deletions
|
@ -7,10 +7,22 @@ import { ensureTypesExist } from '../ensure_types_exist';
|
|||
|
||||
const chance = new Chance();
|
||||
|
||||
const previousWords = new Set();
|
||||
const uniqueWord = () => {
|
||||
const word = chance.word();
|
||||
|
||||
if (previousWords.has(word)) {
|
||||
return uniqueWord();
|
||||
}
|
||||
|
||||
previousWords.add(word);
|
||||
return word;
|
||||
};
|
||||
|
||||
function createRandomTypes(n = chance.integer({ min: 10, max: 20 })) {
|
||||
return chance.n(
|
||||
() => ({
|
||||
name: chance.word(),
|
||||
name: uniqueWord(),
|
||||
mapping: {
|
||||
type: chance.pickone(['keyword', 'text', 'integer', 'boolean'])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue