Skip to content

Commit

Permalink
test: refactor mock api server to fail on error
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Oct 30, 2023
1 parent a2dc395 commit 6add501
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
72 changes: 41 additions & 31 deletions seeder/server.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 6add501

Please sign in to comment.