fix(uptime): проверить RTT через SQL и обновить тестовый стенд
This commit is contained in:
1 parent
ca2b634743
commit
ebe62ae2ef
11 files changed
+1173
-14
No files matched your search
@@ -15,8 +15,8 @@ else {
|
||||
assert(/^mm_accept_166_\d+$/.test(database));assert.equal(new URL(process.env.DATABASE_URL!).pathname,"/"+database)
|
||||
assert.equal((await pool.query("SELECT current_database() AS name")).rows[0].name,database)
|
||||
const prefix="own-measure173-"+Date.now()+"-",probeId=prefix+"probe"
|
||||
let mode:"deny"|"empty"|"loss"|"zero"="deny",requests=0,serverId:number|undefined,cases=0
|
||||
const http=createServer((req,res)=>{requests++;res.setHeader("Content-Type","application/json");if(mode==="deny"){res.statusCode=401;res.end(JSON.stringify({error:401,message:"Unauthorized"}))}else res.end(JSON.stringify(mode==="empty"?[]:[{sent:"4",received:mode==="loss"?"0":"4","packet-loss":mode==="loss"?"100":"0","avg-rtt":"0ms"}]))})
|
||||
let mode:"deny"|"empty"|"loss"|"zero"|"compound"|"malformed"="deny",requests=0,serverId:number|undefined,cases=0
|
||||
const http=createServer((req,res)=>{requests++;res.setHeader("Content-Type","application/json");if(mode==="deny"){res.statusCode=401;res.end(JSON.stringify({error:401,message:"Unauthorized"}))}else res.end(JSON.stringify(mode==="empty"?[]:mode==="malformed"?[{time:"53bad"}]:[{sent:"4",received:mode==="loss"?"0":"4","packet-loss":mode==="loss"?"100":"0","avg-rtt":mode==="compound"?"53ms900us":"0ms"}]))})
|
||||
await new Promise<void>(resolve=>http.listen(0,"127.0.0.1",resolve))
|
||||
const address=http.address();assert(address&&typeof address==="object")
|
||||
const app=Fastify();app.setValidatorCompiler(validatorCompiler);app.setSerializerCompiler(serializerCompiler);await app.register(uptimeRoutes)
|
||||
@@ -36,6 +36,8 @@ else {
|
||||
mode="loss";await collectPingForProbeIds([probeId]);sample=await latest();assert.equal(sample.status,"down");assert.equal(sample.loss,100);assert.equal(sample.rtt,null);cases++
|
||||
mode="zero";await collectPingForProbeIds([probeId]);sample=await latest();assert.equal(sample.status,"up");assert.equal(sample.loss,0);assert.equal(sample.rtt,0);cases++
|
||||
response=await app.inject({method:"GET",url:"/uptime/overview?range=1h"});dto=response.json().probes.find((p:{id:string})=>p.id===probeId);assert.equal(dto.status,"up");assert.equal(dto.loss,0);cases++
|
||||
mode="compound";await collectPingForProbeIds([probeId]);sample=await latest();assert.equal(sample.rtt,54);assert.equal(sample.loss,0);cases++
|
||||
mode="malformed";await collectPingForProbeIds([probeId]);sample=await latest();assert.equal(sample.status,"unknown");assert.equal(sample.rtt,null);assert.equal(sample.loss,null);cases++
|
||||
// Reclassify exact legacy scheduled failures through retained provenance, without guessing real loss.
|
||||
const oldTime=new Date(Date.now()-120_000).toISOString()
|
||||
await pool.query("INSERT INTO uptime_probe_samples(probe_id,sampled_at,status,loss_pct) VALUES($1,$2,'down',100)",[probeId,oldTime])
|
||||
|
||||
Reference in new issue
Block a user