Skip to content

Commit

Permalink
test: check whether payload has expected shape
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Oct 31, 2023
1 parent b834ed1 commit 6ad950b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/docker.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,25 @@ jobs:
- name: Wait for some things to be inserted
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
timeout_minutes: 5
max_attempts: 50
retry_wait_seconds: 2
warning_on_retry: false
command: if (($(docker-compose ${{ env.COMPOSE_ARGS }} logs wdqs-updater | grep "org.wikidata.query.rdf.tool.Updater - Polled" | wc -l) >= 10)); then exit 0; else exit 1; fi
command: |
num_lines=$(docker-compose ${{ env.COMPOSE_ARGS }} logs wdqs-updater | grep "org.wikidata.query.rdf.tool.Updater - Polled" | wc -l)
if [ $num_lines -gt 9 ]; then
exit 0;
else
echo "Found $num_lines lines."
exit 1;
fi
- name: Assert Mock API server did not fail assertions
run: |
num_failures=$(docker-compose ${{ env.COMPOSE_ARGS }} logs api | grep "[FAILURE]" | wc -l)
echo "Found $num_failures failures."
if [ $num_failures -gt 0 ];
then exit 1
fi
- name: Make a sparql request
run: |
NUM_BINDINGS=$(curl 'http://localhost:9999/bigdata/namespace/wdq/sparql' -H 'Accept: application/sparql-results+json' --data-raw 'query=SELECT+*+WHERE%7B+%3Fs+%3Fp+%3Fo+%7D' | jq '.results.bindings | length')
Expand Down
50 changes: 43 additions & 7 deletions seeder/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var http = require('http');
const http = require('http');
const assert = require('assert');
const wbEdit = require( 'wikibase-edit' )( require( './wikibase-edit.config' ) );

let batchId = 1;
Expand All @@ -9,12 +10,45 @@ http.createServer(function (req, res) {
case '/markDone':
case '/markFailed':
if (req.method !== 'POST') {
return { status: 405, body: 'Method not allowed' };
const err = new Error('Method not allowed');
err.status = 405;
return Promise.reject(err);
}
return { status: 200, body: '1' };
return new Promise((resolve, reject) => {
const body = [];
req
.on('error', (err) => {
reject(err);
})
.on('data', (chunk) => {
body.push(chunk);
})
.on('end', () => {
try {
const jsonBody = JSON.parse(
Buffer.concat(body).toString('utf8')
);
assert(
Array.isArray(jsonBody.batches),
'Expected a `batches` property on the request body.'
);
assert(
jsonBody.batches.length,
'Expected `batches` to be a non-empty array.'
);
} catch (err) {
reject(err);
return;
}
console.log('Assertions passed for ', JSON.stringify(jsonBody));
resolve({ status: 200, body: '1' });
})
});
case '/getBatches':
if (req.method !== 'GET') {
return { status: 405, body: 'Method not allowed' };
const err = new Error('Method not allowed');
err.status = 405;
return Promise.reject(err);
}
const numEntities = 20;
const entities = [];
Expand Down Expand Up @@ -54,12 +88,14 @@ http.createServer(function (req, res) {
body: JSON.stringify([responseObject])
};
default:
return { status: 404, body: 'Not found' };
const err = new Error('Not found');
err.status = 404;
return Promise.reject(err);
}
})()
.catch((err) => {
console.error('Failed handling request: %s', err.message);
return { status: 500, body: err.message };
console.error('[FAILURE] Failed handling request: %s', err.message);
return { status: err.status || 500, body: err.message };
})
.then((result) => {
res.writeHead(result.status, result.headers);
Expand Down

0 comments on commit 6ad950b

Please sign in to comment.