-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate health check test for daily.
- Loading branch information
Showing
4 changed files
with
6,062 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const mysql = require("mysql2/promise"); | ||
const redis = require("ioredis"); | ||
|
||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
|
||
describe("Health check", () => { | ||
/* ---------------------- Gateway Server Health Check. ---------------------- */ | ||
it("should return OK if gateways server is healthy", async () => { | ||
try { | ||
const response = await fetch(process.env.GATEWAY_SERVER_URL + "/"); | ||
const data = await response.json(); | ||
expect(data.message).toEqual("ok"); | ||
} catch (error) { | ||
console.error("Gateway server health check failed:", error); | ||
throw error; | ||
} | ||
}); | ||
|
||
/* ------------------------- Ai Server Health Check. ------------------------ */ | ||
// it("should return OK from gateway and ai server both, if ai server is healthy", async () => { | ||
// try { | ||
// // from gateway | ||
// const gatewayResponse = await fetch(process.env.GATEWAY_SERVER_URL + "/ai"); | ||
// const gatewayData = await gatewayResponse.json(); | ||
// expect(gatewayData).toEqual("ok"); | ||
// // from AI | ||
// const aiResponse = await fetch(process.env.AI_SERVER_URL + "/"); | ||
// const aiData = await aiResponse.json(); | ||
// expect(aiData.status).toEqual(200); | ||
// } catch (error) { | ||
// console.error("AI server health check failed:", error); | ||
// throw error; | ||
// } | ||
// }); | ||
|
||
/* --------------------- MySQL Dev-Server Health Check. --------------------- */ | ||
it("should return OK if MySQL dev-server is healthy", async () => { | ||
try { | ||
const connection = await mysql.createConnection({ | ||
host: process.env.MYSQL_HOST, | ||
user: process.env.MYSQL_USER, | ||
password: process.env.MYSQL_PASSWORD, | ||
database: process.env.MYSQL_DATABASE, | ||
}); | ||
|
||
const [rows] = await connection.query("SELECT 1"); | ||
expect(rows).toEqual([{ 1: 1 }]); | ||
await connection.end(); | ||
} catch (error) { | ||
console.error("MySQL health check failed:", error); | ||
throw error; | ||
} | ||
}); | ||
|
||
/* --------------------- Redis Dev-Server Health Check. --------------------- */ | ||
it("should return OK if Redis dev-server is healthy", async () => { | ||
const client = redis.createClient({ | ||
host: process.env.REDIS_HOST, | ||
password: process.env.REDIS_PASSWORD, | ||
port: process.env.REDIS_PORT, | ||
}); | ||
|
||
try { | ||
await new Promise((resolve, reject) => { | ||
client.on("connect", resolve); | ||
client.on("error", reject); | ||
}); | ||
expect(client.status).toEqual("connect"); | ||
} catch (error) { | ||
console.error("Redis health check failed:", error); | ||
throw error; | ||
} finally { | ||
await client.quit(); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.