From 6add50195e5f07bfe98e8d36f51077955f5e7c2a Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Mon, 30 Oct 2023 14:35:41 +0100 Subject: [PATCH] test: refactor mock api server to fail on error --- docker-compose.ci.yml | 2 +- seeder/server.js | 72 ++++++++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index e1bd9db..80195c2 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -27,7 +27,7 @@ services: environment: - WBSTACK_WIKIBASE_SCHEME=http - WBSTACK_LOOP_LIMIT=100 - - WBSTACK_API_ENDPOINT=http://api.svc:3030 + - WBSTACK_API_ENDPOINT=http://api.svc:3030/getBatches - WBSTACK_BATCH_SLEEP=1 - WIKIBASE_HOST=wikibase.svc - HEAP_SIZE=32m diff --git a/seeder/server.js b/seeder/server.js index 00c55ec..f993e96 100644 --- a/seeder/server.js +++ b/seeder/server.js @@ -1,41 +1,51 @@ var http = require('http'); const wbEdit = require( 'wikibase-edit' )( require( './wikibase-edit.config' ) ); -var x = 0 -http.createServer(async function (req, res) { - res.writeHead(200, {'Content-Type': 'text/json'}); +http.createServer(function (req, res) { + (async () => { + switch (req.url) { + case '/getBatches': + const numEntities = 20; + const entities = []; - numEntities = 20; - entities = []; + for (let i = 1; i <= numEntities; ++i) { + const { entity } = await wbEdit.entity.create({ + type: 'item', + labels: { + 'en': new Date().toISOString() + }, + descriptions: { + 'en': new Date().toDateString() + new Date().toISOString() + } + }); - for(var i=1; i <= numEntities; ++i){ - const { entity } = await wbEdit.entity.create({ - type: 'item', - labels: { - 'en': new Date().toISOString() - }, - descriptions: { - 'en': new Date().toDateString() + new Date().toISOString() + console.log('created item id', entity.id) + entities.push(entity.id) } - }); - console.log('created item id', entity.id) - entities.push(entity.id) - } + console.log(new Date().toISOString()); - x += numEntities; - console.log(new Date().toISOString()); + responseObject = { + 'entityIds': entities.join(','), + 'wiki': { + 'domain': process.env.API_WIKIBASE_DOMAIN, + 'wiki_queryservice_namespace': { + 'backend': process.env.API_WDQS_BACKEND, + 'namespace': 'wdq' + } + }, - responseObject = { - 'entityIds': entities.join(','), - 'wiki': { - 'domain': process.env.API_WIKIBASE_DOMAIN, - 'wiki_queryservice_namespace': { - 'backend': process.env.API_WDQS_BACKEND, - 'namespace': 'wdq' - } - }, - - }; - res.end(JSON.stringify([responseObject])); + }; + res.writeHead(200, {'Content-Type': 'text/json'}); + res.end(JSON.stringify([responseObject])); + default: + res.writeHead(404); + res.end('Not found'); + } + })() + .catch((err) => { + console.error('Failed handling request: %s', err.message); + res.writeHead(500); + res.end(err.message); + }) }).listen(3030);