Skip to content

Commit

Permalink
Tools: Added testing command to create many items in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Oct 31, 2021
1 parent ab86812 commit 22d472d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/app-cli/app/command-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { reg } from '@joplin/lib/registry';
import Note from '@joplin/lib/models/Note';
import uuid from '@joplin/lib/uuid';
import populateDatabase from '@joplin/lib/services/debug/populateDatabase';
import { readCredentialFile } from '@joplin/lib/utils/credentialFiles';
import JoplinServerApi from '@joplin/lib/JoplinServerApi';

function randomElement(array: any[]): any {
if (!array.length) return null;
Expand Down Expand Up @@ -87,6 +89,38 @@ class Command extends BaseCommand {
}
}

if (command === 'joplinServerParallelItemUpdate') {
const randomContent = () => {
const charCount = Math.random() * 1000;
return 'a'.repeat(charCount);
};

const joplinServerAuth = JSON.parse(await readCredentialFile('joplin-server-test.json'));

const api = new JoplinServerApi({
baseUrl: () => joplinServerAuth.baseUrl,
userContentBaseUrl: () => joplinServerAuth.userContentBaseUrl,
username: () => joplinServerAuth.email,
password: () => joplinServerAuth.password,
});

const apiPut = async () => {
await api.exec('PUT', 'api/items/root:/testing:/content', {}, randomContent(), {
'Content-Type': 'application/octet-stream',
});
};

await apiPut();

const promises = [];
for (let i = 0; i < 100; i++) {
promises.push(void apiPut());
}
await Promise.all(promises);

console.info(await api.exec('GET', 'api/items/root:/testing:'));
}

await Promise.all(promises);
}

Expand Down

0 comments on commit 22d472d

Please sign in to comment.