Files
mtusi2026lab7/evidence/openbao/health-convergence-red.txt

70 lines
6.7 KiB
Plaintext

bun test v1.4.4 (38afee6c8)
student-tests/health-convergence.test.ts:
1 | export function createHealthConvergence(ports:{read:()=>Promise<string>;now:()=>number;sleep:(milliseconds:number)=>Promise<void>},budgetMilliseconds:number,pollMilliseconds:number) {
2 | if([ports?.read,ports?.now,ports?.sleep].some(p=>typeof p!=="function"))throw Error("HEALTH_PORTS_REQUIRED");
3 | if(!Number.isSafeInteger(budgetMilliseconds)||!Number.isSafeInteger(pollMilliseconds)||pollMilliseconds<=0||budgetMilliseconds<pollMilliseconds)throw Error("HEALTH_LIMITS_INVALID");
4 | return async()=>{
5 | const started=ports.now();if(!Number.isFinite(started)||started<0)throw Error("HEALTH_CLOCK_INVALID");
6 | const state=await ports.read();if(state!=="healthy")throw Error("BAO_HEALTH_NOT_CONVERGED");
^
error: BAO_HEALTH_NOT_CONVERGED
at <anonymous> (/Users/rey/mtuci/vp/lab7/scripts/health-convergence.ts:6:63)
at async <anonymous> (/Users/rey/mtuci/vp/lab7/student-tests/health-convergence.test.ts:3:204)
(fail) wait for the next healthy tick after unseal instead of trusting stale unhealthy [1.07ms]
(pass) healthy container returns immediately without delaying recovery [0.07ms]
1 | import {test,expect} from 'bun:test';import {createHealthConvergence} from '../scripts/health-convergence';
2 | function fixture(states:string[]){let now=1000,reads=0;const slept:number[]=[];return {slept,ports:{read:async()=>states[Math.min(reads++,states.length-1)],now:()=>now,sleep:async(ms:number)=>{slept.push(ms);now+=ms;}}};}
3 | test('wait for the next healthy tick after unseal instead of trusting stale unhealthy',async()=>{const f=fixture(['unhealthy','starting','healthy']);expect(await createHealthConvergence(f.ports,5000,1000)()).toEqual({elapsedMilliseconds:2000,reads:3});expect(f.slept).toEqual([1000,1000]);});
4 | test('healthy container returns immediately without delaying recovery',async()=>{const f=fixture(['healthy']);expect(await createHealthConvergence(f.ports,5000,1000)()).toEqual({elapsedMilliseconds:0,reads:1});expect(f.slept).toEqual([]);});
5 | test('never healthy fails at the bounded deadline',async()=>{const f=fixture(['unhealthy']);await expect(createHealthConvergence(f.ports,2000,1000)()).rejects.toThrow('BAO_HEALTH_NOT_CONVERGED');expect(f.slept).toEqual([1000,1000]);});
^
error: expect(received).toEqual(expected)
- [
- 1000,
- 1000,
- ]
+ []
- Expected - 4
+ Received + 1
at <anonymous> (/Users/rey/mtuci/vp/lab7/student-tests/health-convergence.test.ts:5:212)
(fail) never healthy fails at the bounded deadline [2.27ms]
(pass) native read failure preserves its original identity [0.06ms]
2 | function fixture(states:string[]){let now=1000,reads=0;const slept:number[]=[];return {slept,ports:{read:async()=>states[Math.min(reads++,states.length-1)],now:()=>now,sleep:async(ms:number)=>{slept.push(ms);now+=ms;}}};}
3 | test('wait for the next healthy tick after unseal instead of trusting stale unhealthy',async()=>{const f=fixture(['unhealthy','starting','healthy']);expect(await createHealthConvergence(f.ports,5000,1000)()).toEqual({elapsedMilliseconds:2000,reads:3});expect(f.slept).toEqual([1000,1000]);});
4 | test('healthy container returns immediately without delaying recovery',async()=>{const f=fixture(['healthy']);expect(await createHealthConvergence(f.ports,5000,1000)()).toEqual({elapsedMilliseconds:0,reads:1});expect(f.slept).toEqual([]);});
5 | test('never healthy fails at the bounded deadline',async()=>{const f=fixture(['unhealthy']);await expect(createHealthConvergence(f.ports,2000,1000)()).rejects.toThrow('BAO_HEALTH_NOT_CONVERGED');expect(f.slept).toEqual([1000,1000]);});
6 | test('native read failure preserves its original identity',async()=>{const f=fixture(['healthy']),error=Error('FIXTURE_READ');f.ports.read=async()=>{throw error;};let actual;try{await createHealthConvergence(f.ports,5000,1000)();}catch(e){actual=e;}expect(actual).toBe(error);});
7 | test('unknown state fails closed',async()=>{const f=fixture(['unknown']);await expect(createHealthConvergence(f.ports,5000,1000)()).rejects.toThrow('BAO_HEALTH_INVALID');});
^
error: expect(received).toThrow(expected)
Expected substring: "BAO_HEALTH_INVALID"
Received message: "BAO_HEALTH_NOT_CONVERGED"
at <anonymous> (/Users/rey/mtuci/vp/lab7/student-tests/health-convergence.test.ts:7:141)
(fail) unknown state fails closed [0.27ms]
3 | test('wait for the next healthy tick after unseal instead of trusting stale unhealthy',async()=>{const f=fixture(['unhealthy','starting','healthy']);expect(await createHealthConvergence(f.ports,5000,1000)()).toEqual({elapsedMilliseconds:2000,reads:3});expect(f.slept).toEqual([1000,1000]);});
4 | test('healthy container returns immediately without delaying recovery',async()=>{const f=fixture(['healthy']);expect(await createHealthConvergence(f.ports,5000,1000)()).toEqual({elapsedMilliseconds:0,reads:1});expect(f.slept).toEqual([]);});
5 | test('never healthy fails at the bounded deadline',async()=>{const f=fixture(['unhealthy']);await expect(createHealthConvergence(f.ports,2000,1000)()).rejects.toThrow('BAO_HEALTH_NOT_CONVERGED');expect(f.slept).toEqual([1000,1000]);});
6 | test('native read failure preserves its original identity',async()=>{const f=fixture(['healthy']),error=Error('FIXTURE_READ');f.ports.read=async()=>{throw error;};let actual;try{await createHealthConvergence(f.ports,5000,1000)();}catch(e){actual=e;}expect(actual).toBe(error);});
7 | test('unknown state fails closed',async()=>{const f=fixture(['unknown']);await expect(createHealthConvergence(f.ports,5000,1000)()).rejects.toThrow('BAO_HEALTH_INVALID');});
8 | test('backward clock is rejected',async()=>{const f=fixture(['unhealthy']);let ticks=0;f.ports.now=()=>ticks++===0?1000:999;await expect(createHealthConvergence(f.ports,5000,1000)()).rejects.toThrow('HEALTH_CLOCK_INVALID');});
^
error: expect(received).toThrow(expected)
Expected substring: "HEALTH_CLOCK_INVALID"
Received message: "BAO_HEALTH_NOT_CONVERGED"
at <anonymous> (/Users/rey/mtuci/vp/lab7/student-tests/health-convergence.test.ts:8:192)
(fail) backward clock is rejected [0.09ms]
(pass) explicit ports are required [0.02ms]
3 pass
4 fail
8 expect() calls
Ran 7 tests across 1 file. [17.00ms]