fix health-check for upload

This commit is contained in:
Karol Wypchlo 2021-01-26 12:44:34 +01:00
parent 8a44499ceb
commit 7b6bf6664f
2 changed files with 9 additions and 1 deletions

View File

@ -12,6 +12,7 @@
"lowdb": "^1.0.0", "lowdb": "^1.0.0",
"object-hash": "^2.1.1", "object-hash": "^2.1.1",
"superagent": "^6.0.0", "superagent": "^6.0.0",
"tmp": "^0.2.1",
"yargs": "^16.2.0" "yargs": "^16.2.0"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,15 +1,22 @@
const fs = require("fs");
const superagent = require("superagent"); const superagent = require("superagent");
const tmp = require('tmp');
const { StatusCodes } = require("http-status-codes"); const { StatusCodes } = require("http-status-codes");
const { calculateElapsedTime, getResponseContent } = require("../utils"); const { calculateElapsedTime, getResponseContent } = require("../utils");
// uploadCheck returns the result of uploading a sample file // uploadCheck returns the result of uploading a sample file
async function uploadCheck(done) { async function uploadCheck(done) {
const time = process.hrtime(); const time = process.hrtime();
const file = tmp.fileSync();
fs.writeSync(file.fd, Buffer.from(new Date())); // write current date to temp file
superagent superagent
.post(`${process.env.PORTAL_URL}/skynet/skyfile`) .post(`${process.env.PORTAL_URL}/skynet/skyfile`)
.attach("file", "package.json", "package.json") .attach("file", file.name, file.name)
.end((error, response) => { .end((error, response) => {
file.removeCallback();
const statusCode = (response && response.statusCode) || (error && error.statusCode) || null; const statusCode = (response && response.statusCode) || (error && error.statusCode) || null;
done({ done({