Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add http rsr #285

Merged
merged 15 commits into from
Jan 10, 2025
43 changes: 38 additions & 5 deletions stats/test/handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,13 @@ describe('HTTP request handler', () => {
])
})
it('handles successful_http values 0, null, undefined', async () => {
bajtos marked this conversation as resolved.
Show resolved Hide resolved
await givenRetrievalStats(pgPools.evaluate, { day: '2024-01-20', total: 10, successful: 1, successfulHttp: 0 })
await givenRetrievalStats(pgPools.evaluate, { day: '2024-01-21', total: 10, successful: 1, successfulHttp: undefined })
await givenRetrievalStats(pgPools.evaluate, { day: '2024-01-22', total: 10, successful: 1, successfulHttp: null })
await givenRetrievalStats(pgPools.evaluate, { day: '2024-01-20', minerId: 'f1one', total: 10, successful: 1, successfulHttp: 0 })
await givenRetrievalStats(pgPools.evaluate, { day: '2024-01-21', minerId: 'f1one', total: 10, successful: 1, successfulHttp: undefined })
await givenRetrievalStats(pgPools.evaluate, { day: '2024-01-22', minerId: 'f1one', total: 10, successful: 1, successfulHttp: null })
await givenRetrievalStats(pgPools.evaluate, { day: '2024-01-23', minerId: 'f2two', total: 10, successful: 1, successfulHttp: undefined })
await givenRetrievalStats(pgPools.evaluate, { day: '2024-01-24', minerId: 'f3three', total: 20, successful: 2, successfulHttp: null })

const res = await fetch(
let res = await fetch(
new URL(
'/retrieval-success-rate?from=2024-01-20&to=2024-01-22',
baseUrl
Expand All @@ -237,12 +239,43 @@ describe('HTTP request handler', () => {
}
)
await assertResponseStatus(res, 200)
const stats = await res.json()
let stats = await res.json()
assert.deepStrictEqual(stats, [
{ day: '2024-01-20', success_rate: 0.1, successful: '1', total: '10', successful_http: '0', success_rate_http: 0 },
{ day: '2024-01-21', success_rate: 0.1, successful: '1', total: '10', successful_http: null, success_rate_http: null },
{ day: '2024-01-22', success_rate: 0.1, successful: '1', total: '10', successful_http: null, success_rate_http: null }
])

res = await fetch(
new URL(
'/miners/retrieval-success-rate/summary?from=2024-01-20&to=2024-01-22',
bajtos marked this conversation as resolved.
Show resolved Hide resolved
baseUrl
), {
redirect: 'manual'
}
)
await assertResponseStatus(res, 200)
stats = await res.json()
assert.deepStrictEqual(stats, [
// If there is a single number we expect any undefined or null values to be converted to 0 by Postgres
{ miner_id: 'f1one', total: '30', successful: '3', success_rate: 0.1, successful_http: '0', success_rate_http: 0 }
])

res = await fetch(
new URL(
'/miners/retrieval-success-rate/summary?from=2024-01-23&to=2024-01-24',
baseUrl
), {
redirect: 'manual'
}
)
await assertResponseStatus(res, 200)
stats = await res.json()
assert.deepStrictEqual(stats, [
{ miner_id: 'f2two', total: '10', successful: '1', success_rate: 0.1, successful_http: null, success_rate_http: null },
{ miner_id: 'f3three', total: '20', successful: '2', success_rate: 0.1, successful_http: null, success_rate_http: null }
]
)
})
})

Expand Down
Loading