function getContentType(type) { switch (type) { case STRING: return'text/plain;charset=UTF-8'; case ARRAYBUFFER: returnnull; case FORM: return'multipart/form-data'; case BLOB: returnnull; default: throw Error(`invalid type: ${type}`);
}
}
// Create a payload with the given size and type. // `sizeString` must be one of EMPTY, SMALL, LARGE, MAX, TOOLARGE. // `type` must be one of STRING, ARRAYBUFFER, FORM, BLOB. // `contentType` is effective only if `type` is BLOB. function makePayload(sizeString, type, contentType) {
let size = 0; switch (sizeString) { case EMPTY:
size = 0; break; case SMALL:
size = 10; break; case LARGE:
size = 10 * 1000; break; case MAX: if (type === FORM) { throw Error('Not supported');
}
size = 65536; break; case TOOLARGE:
size = 65537; break; default: throw Error('invalid size');
}
let data = ''; if (size > 0) { const prefix = String(size) + ':';
data = prefix + Array(size - prefix.length).fill('*').join('');
}
switch (type) { case STRING: return data; case ARRAYBUFFER: returnnew TextEncoder().encode(data).buffer; case FORM: const formData = new FormData(); if (size > 0) {
formData.append('payload', data);
} return formData; case BLOB: const options = contentType ? {type: contentType} : undefined; const blob = new Blob([data], options); return blob; default: throw Error('invalid type');
}
}
// Poll the server for the test result.
async function waitForResult(id, expectedError = null) { const url = `/beacon/resources/beacon.py?cmd=stat&id=${id}`; for (let i = 0; i < 30; ++i) { const response = await fetch(url); const text = await response.text(); const results = JSON.parse(text);
if (results.length === 0) {
await new Promise(resolve => step_timeout(resolve, 100)); continue;
}
assert_equals(results.length, 1, `bad response: '${text}'`); const result = results[0]; // null JSON values parse as null, not undefined
assert_equals(result.error, expectedError, 'error recorded in stash'); return result;
}
assert_true(false, 'timeout');
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.