Skip to content

Commit

Permalink
add assertResponse handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lai committed Sep 18, 2024
1 parent 1aee750 commit 615bb91
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
1 change: 1 addition & 0 deletions apiTests/merged-tests.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/pages/studyView/rfc80Tester.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export const RFC80Test = observer(function() {
test.url,
test.data,
test.label,
test.hash
test.hash,
col.assertResponse
).then((report: any) => {
report.test = test;
place = place + 1;
Expand Down
77 changes: 49 additions & 28 deletions src/shared/api/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ export function validate(
label: string,
hash: number,
body?: any,
elapsedTime?: any
elapsedTime?: any,
assertResponse?: any[]
) {
const clStart = performance.now();
let chDuration: number, legacyDuration: number;
Expand All @@ -270,27 +271,39 @@ export function validate(

return chXHR
.then(({ body, elapsedTime }: any) => {
let legacyUrl = url.replace(/column-store\//, '');
if (treatmentLegacyUrl[label]) {
legacyUrl = treatmentLegacyUrl[label](legacyUrl);
if (!assertResponse) {
let legacyUrl = url.replace(/column-store\//, '');
if (treatmentLegacyUrl[label]) {
legacyUrl = treatmentLegacyUrl[label](legacyUrl);
}
const legacyXHR = $.ajax({
method: 'post',
url: legacyUrl,
data: JSON.stringify(params),
contentType: 'application/json',
});
return legacyXHR.then(legacyResult => {
const result: any = compareCounts(body, legacyResult, label);
result.url = url;
result.hash = hash;
result.data = params;
result.chDuration = parseFloat(elapsedTime);
result.legacyDuration = parseFloat(
legacyXHR.getResponseHeader('elapsed-time') || ''
);
return result;
});
}
else {
return {
label,
url: url,
hash: hash,
status: true,
data: params,
chDuration: parseFloat(elapsedTime),
};
}
const legacyXHR = $.ajax({
method: 'post',
url: legacyUrl,
data: JSON.stringify(params),
contentType: 'application/json',
});
return legacyXHR.then(legacyResult => {
const result: any = compareCounts(body, legacyResult, label);
result.url = url;
result.hash = hash;
result.data = params;
result.chDuration = parseFloat(elapsedTime);
result.legacyDuration = parseFloat(
legacyXHR.getResponseHeader('elapsed-time') || ''
);
return result;
});
})
.catch(() => {
const result: any = {};
Expand Down Expand Up @@ -324,13 +337,21 @@ export function reportValidationResult(result: any, prefix = '') {
});

result.status &&
console.log(
`${prefix} ${result.label} (${
result.hash
}) passed :) ch: ${result.chDuration.toFixed(
0
)} legacy: ${result.legacyDuration.toFixed(0)}`
);
(!result.legacyDuration
? console.log(
`${prefix} ${result.label} (${
result.hash
}) assertResponse detected, passed :) ch: ${result.chDuration.toFixed(
0
)}`
)
: console.log(
`${prefix} ${result.label} (${
result.hash
}) passed :) ch: ${result.chDuration.toFixed(
0
)} legacy: ${result.legacyDuration.toFixed(0)}`
));

if (!result.status) {
_.forEach(result.clDataSorted, (cl: any, i: number) => {
Expand Down

0 comments on commit 615bb91

Please sign in to comment.