Skip to content

Agent Mesh

fix flakiness

Antonio Ojea22c6f465305f
diff --git a/cmd/sam-node/gate_test.go b/cmd/sam-node/gate_test.go
index 25a0241a..4220a2c2 100644
--- a/cmd/sam-node/gate_test.go
+++ b/cmd/sam-node/gate_test.go
@@ -125,6 +125,7 @@ func startBareNode(t *testing.T, ctx context.Context) (*SamNode, func()) {
MonitorBootstrap: 2 * time.Minute,
MonitorInterval: 1 * time.Minute,
TrustHubRBAC: true,
+ BiscuitTimeout: 500 * time.Millisecond,
})
if err != nil {
t.Fatal(err)
diff --git a/cmd/sam-node/middleware.go b/cmd/sam-node/middleware.go
index ead67afd..818a002e 100644
--- a/cmd/sam-node/middleware.go
+++ b/cmd/sam-node/middleware.go
@@ -24,6 +24,7 @@ import (
"strings"
"github.com/biscuit-auth/biscuit-go/v2"
+ "github.com/biscuit-auth/biscuit-go/v2/datalog"
"github.com/biscuit-auth/biscuit-go/v2/parser"
"github.com/google/sam/api"
"github.com/libp2p/go-libp2p/core/network"
@@ -260,7 +261,11 @@ func (n *SamNode) Authorize(rawToken []byte, req RequestContext, pubKey ed25519.
return fmt.Errorf("invalid biscuit: %w", err)
}
- authorizer, err := b.Authorizer(pubKey)
+ var authOpts []biscuit.AuthorizerOption
+ if n.BiscuitTimeout > 0 {
+ authOpts = append(authOpts, biscuit.WithWorldOptions(datalog.WithMaxDuration(n.BiscuitTimeout)))
+ }
+ authorizer, err := b.Authorizer(pubKey, authOpts...)
if err != nil {
return err
}
diff --git a/cmd/sam-node/node.go b/cmd/sam-node/node.go
index 0c83b43e..b976a61d 100644
--- a/cmd/sam-node/node.go
+++ b/cmd/sam-node/node.go
@@ -133,6 +133,7 @@ type SamNode struct {
authOnce sync.Once
currentRelays []peer.AddrInfo
reprovideTrigger chan struct{}
+ BiscuitTimeout time.Duration
}
// UpdateRelays updates the current relays used by AutoRelay.
@@ -169,6 +170,7 @@ type SamNodeConfig struct {
AutoRelayBootDelay time.Duration
AutoRelayBackoff time.Duration
TrustHubRBAC bool
+ BiscuitTimeout time.Duration
}
// NewSamNode creates a new Agent instance secured with the 4-layer pipeline.
@@ -191,6 +193,8 @@ func NewSamNode(ctx context.Context, cfg SamNodeConfig) (*SamNode, error) {
reprovideTrigger: make(chan struct{}, 1),
}
+ node.BiscuitTimeout = cfg.BiscuitTimeout
+
var err error
node.rateLimiter, err = NewPeerRateLimiter(RateLimiterSize)
if err != nil {
diff --git a/cmd/sam-node/proxy_test.go b/cmd/sam-node/proxy_test.go
index 659c3055..00e2aa8e 100644
--- a/cmd/sam-node/proxy_test.go
+++ b/cmd/sam-node/proxy_test.go
@@ -66,6 +66,7 @@ func TestDatapathIntegration(t *testing.T) {
AllowLoopback: true,
MonitorBootstrap: 2 * time.Minute,
MonitorInterval: 1 * time.Minute,
+ BiscuitTimeout: 500 * time.Millisecond,
})
if err != nil {
t.Fatal(err)
@@ -89,6 +90,7 @@ func TestDatapathIntegration(t *testing.T) {
AllowLoopback: true,
MonitorBootstrap: 2 * time.Minute,
MonitorInterval: 1 * time.Minute,
+ BiscuitTimeout: 500 * time.Millisecond,
})
if err != nil {
t.Fatal(err)
@@ -251,6 +253,7 @@ func TestStdioDatapathIntegration(t *testing.T) {
AllowLoopback: true,
MonitorBootstrap: 2 * time.Minute,
MonitorInterval: 1 * time.Minute,
+ BiscuitTimeout: 500 * time.Millisecond,
})
if err != nil {
t.Fatal(err)
@@ -270,6 +273,7 @@ func TestStdioDatapathIntegration(t *testing.T) {
AllowLoopback: true,
MonitorBootstrap: 2 * time.Minute,
MonitorInterval: 1 * time.Minute,
+ BiscuitTimeout: 500 * time.Millisecond,
})
if err != nil {
t.Fatal(err)
diff --git a/tests/integration/failover_test.go b/tests/integration/failover_test.go
index 0666822b..2d13bfb4 100644
--- a/tests/integration/failover_test.go
+++ b/tests/integration/failover_test.go
@@ -190,12 +190,12 @@ roles: {}
// Wait for Node B's AutoRelay to get updated
for i := 0; i < 150; i++ {
out = stdoutNode.String() + stderrNode.String()
- if strings.Contains(out, "Successfully reconnected to Hub via HTTP fallback.") {
+ if strings.Contains(out, "Successfully reconnected to Hub via HTTP fallback") {
break
}
time.Sleep(100 * time.Millisecond)
}
- if !strings.Contains(out, "Successfully reconnected to Hub via HTTP fallback.") {
+ if !strings.Contains(out, "Successfully reconnected to Hub via HTTP fallback") {
t.Fatalf("Node B failed to detect failover and reconnect.\nOutput:\n%s", out)
}
t.Log("Node B successfully reconnected to Hub B!")