okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
a6d8ebe
main
1/// Concurrent ownership of one home conflicts with the one-daemon E2E harness. 2import albedo/daemon/server 3import gleam/erlang/process 4import gleam/result 5import gleeunit/should 6 7@external ( erlang , "albedo_skills_test_support" , "fixture" ) 8fn fixture () -> #( String , String , String ) 9 10@external ( erlang , "albedo_skills_test_support" , "cleanup" ) 11fn cleanup ( root : String ) -> Nil 12 13pub fn second_daemon_cannot_claim_a_held_home_test () -> Nil { 14let #( root , _ , home ) = fixture () 15let claimed = process . new_subject () 16// A subject only delivers to the process that created it, so the owner makes 17// its own release subject and hands it back. 18process . spawn ( fn () { 19let release = process . new_subject () 20process . send ( claimed , #( server . claim_home ( home ), release )) 21process . receive_forever ( release ) 22}) 23let assert Ok (#( first , release )) = process . receive ( claimed , 5000 ) 24first |> should . equal ( Ok ( Nil )) 25 26server . claim_home ( home ) 27|> result . map_error ( fn ( _ ) { Nil }) 28|> should . equal ( Error ( Nil )) 29 30// The connection closes when the owner's resources are freed, which can land 31// just after its exit is observable, so a fresh claimant retries briefly. 32process . send ( release , Nil ) 33claim_eventually ( home , 50 ) |> should . equal ( Ok ( Nil )) 34 35cleanup ( root ) 36} 37 38fn claim_eventually ( home : String , attempts : Int ) -> Result ( Nil , Nil ) { 39let reply = process . new_subject () 40process . spawn ( fn () { process . send ( reply , server . claim_home ( home )) }) 41case process . receive ( reply , 5000 ) { 42Ok ( Ok ( Nil )) -> Ok ( Nil ) 43_ if attempts > 1 -> { 44process . sleep ( 20 ) 45claim_eventually ( home , attempts - 1 ) 46} 47_ -> Error ( Nil ) 48} 49}