diff --git a/packages/app-cli/app/command-testing.ts b/packages/app-cli/app/command-testing.ts index aa438ba7700..f137a92f9e3 100644 --- a/packages/app-cli/app/command-testing.ts +++ b/packages/app-cli/app/command-testing.ts @@ -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; @@ -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); }