- Any failure of a request the link may have delivered now says the line may have run; "nothing ran" is said only of a request the link knows it never asked (no link open, nobody listening: link.ErrNotAsked). - A test holds that a connection saying nothing is answered within its deadline, set at accept, and gives its slot back. - The README says the socket refuses a process outside the machine's own namespaces, so flatpak, toolbox and distrobox shells are refused.
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
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)
|
|
}
|
|
}
|