-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: refactor mock api server to fail on error #141
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,5 @@ | ||
version: '2' | ||
services: | ||
|
||
wikibase: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really know what these overrides are good for. Containers can use the Docker network (instead of the host one) in both CI and local testing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no clue either.. let's not keep it |
||
networks: | ||
default: | ||
aliases: | ||
- some-cool-internal-hostname.svc | ||
|
||
api: | ||
environment: | ||
- API_WIKIBASE_DOMAIN=wikibase.svc | ||
- API_WDQS_BACKEND=wdqs.svc:9999 | ||
- WBSTACK_PROXYMAP_INGRESS="some-cool-internal-hostname.svc:80" | ||
|
||
wdqs-updater: | ||
build: | ||
context: . | ||
|
@@ -27,7 +14,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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,52 @@ | ||
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'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having this as the first line meant we'd 200 even when wikibase was still down. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice catch |
||
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])); | ||
return; | ||
default: | ||
res.writeHead(404); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this; good idea to ensure it 404s everywhere else |
||
res.end('Not found'); | ||
} | ||
})() | ||
.catch((err) => { | ||
console.error('Failed handling request: %s', err.message); | ||
res.writeHead(500); | ||
res.end(err.message); | ||
}) | ||
}).listen(3030); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this has some background, but I cannot bind to port 80 locally using docker compose unless I elevate priviliges.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is no reason to keep this like it is; I guess it was just picked at some point to look closest to prod. After all these port names end up in the URIs of the triples that go in the queryservice