package meshcli import ( "context" "net" "strings" "testing" "time" "git.novox.be/novox/mesh-sdk/go/cli" ) // **A connection that says nothing is bounded from the moment it is accepted** (review of ADR 0272): its deadline is // set before any lookup, so it is answered and closed within readWithin, holds no slot after, and asks nothing. func TestAConnectionThatSaysNothingIsAnsweredWithinItsDeadline(t *testing.T) { was := readWithin readWithin = 200 * time.Millisecond t.Cleanup(func() { readWithin = was }) asked := false socket := serving(t, func(context.Context, Asked) cli.Answer { asked = true return cli.Answer{} }) conn, err := net.Dial("unix", socket) if err != nil { t.Fatal(err) } defer conn.Close() _ = conn.SetDeadline(time.Now().Add(5 * time.Second)) a, err := cli.ReadAnswer(conn) if err != nil { t.Fatalf("a silent connection was not answered within its deadline: %v", err) } if asked || a.Refused == "" || !strings.Contains(a.Refused, "nothing was asked") { t.Fatalf("a silent connection was asked (%v) or answered %+v", asked, a) } // Its slot was given back: the account's next line is not busy. b, err := cli.Ask(context.Background(), socket, []string{"status"}) if err != nil || strings.Contains(b.Refused, "busy") || !asked { t.Fatalf("the next line after a silent one reads %+v (%v), asked %v", b, err, asked) } }