Files
s3/weed/mq/kafka/consumer/static_membership_test.go
zooqueen dd74d3e6d6 Replace AGPL MinIO fork with Apache-2.0 SeaweedFS fork; rebrand CLI weed->s3
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.

- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
  "Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
  SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
  (replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
  keep their upstream import paths with zero churn. Internal identifiers and
  import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
  help/usage/flag strings, shell autocomplete program name, and the product name
  in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
  (e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
  `cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
  updated to ignore the `s3` build output.
2026-06-18 23:41:25 -07:00

197 lines
5.2 KiB
Go

package consumer
import (
"testing"
"time"
)
func TestGroupCoordinator_StaticMembership(t *testing.T) {
gc := NewGroupCoordinator()
defer gc.Close()
group := gc.GetOrCreateGroup("test-group")
// Test static member registration
instanceID := "static-instance-1"
member := &GroupMember{
ID: "member-1",
ClientID: "client-1",
ClientHost: "localhost",
GroupInstanceID: &instanceID,
SessionTimeout: 30000,
State: MemberStatePending,
LastHeartbeat: time.Now(),
JoinedAt: time.Now(),
}
// Add member to group
group.Members[member.ID] = member
gc.RegisterStaticMember(group, member)
// Test finding static member
foundMember := gc.FindStaticMember(group, instanceID)
if foundMember == nil {
t.Error("Expected to find static member, got nil")
}
if foundMember.ID != member.ID {
t.Errorf("Expected member ID %s, got %s", member.ID, foundMember.ID)
}
// Test IsStaticMember
if !gc.IsStaticMember(member) {
t.Error("Expected member to be static")
}
// Test dynamic member (no instance ID)
dynamicMember := &GroupMember{
ID: "member-2",
ClientID: "client-2",
ClientHost: "localhost",
GroupInstanceID: nil,
SessionTimeout: 30000,
State: MemberStatePending,
LastHeartbeat: time.Now(),
JoinedAt: time.Now(),
}
if gc.IsStaticMember(dynamicMember) {
t.Error("Expected member to be dynamic")
}
// Test unregistering static member
gc.UnregisterStaticMember(group, instanceID)
foundMember = gc.FindStaticMember(group, instanceID)
if foundMember != nil {
t.Error("Expected static member to be unregistered")
}
}
func TestGroupCoordinator_StaticMemberReconnection(t *testing.T) {
gc := NewGroupCoordinator()
defer gc.Close()
group := gc.GetOrCreateGroup("test-group")
instanceID := "static-instance-1"
// First connection
member1 := &GroupMember{
ID: "member-1",
ClientID: "client-1",
ClientHost: "localhost",
GroupInstanceID: &instanceID,
SessionTimeout: 30000,
State: MemberStatePending,
LastHeartbeat: time.Now(),
JoinedAt: time.Now(),
}
group.Members[member1.ID] = member1
gc.RegisterStaticMember(group, member1)
// Simulate disconnection and reconnection with same instance ID
delete(group.Members, member1.ID)
// Reconnection with same instance ID should reuse the mapping
member2 := &GroupMember{
ID: "member-2", // Different member ID
ClientID: "client-1",
ClientHost: "localhost",
GroupInstanceID: &instanceID, // Same instance ID
SessionTimeout: 30000,
State: MemberStatePending,
LastHeartbeat: time.Now(),
JoinedAt: time.Now(),
}
group.Members[member2.ID] = member2
gc.RegisterStaticMember(group, member2)
// Should find the new member with the same instance ID
foundMember := gc.FindStaticMember(group, instanceID)
if foundMember == nil {
t.Error("Expected to find static member after reconnection")
}
if foundMember.ID != member2.ID {
t.Errorf("Expected member ID %s, got %s", member2.ID, foundMember.ID)
}
}
func TestGroupCoordinator_StaticMembershipEdgeCases(t *testing.T) {
gc := NewGroupCoordinator()
defer gc.Close()
group := gc.GetOrCreateGroup("test-group")
// Test empty instance ID
member := &GroupMember{
ID: "member-1",
ClientID: "client-1",
ClientHost: "localhost",
GroupInstanceID: nil,
SessionTimeout: 30000,
State: MemberStatePending,
LastHeartbeat: time.Now(),
JoinedAt: time.Now(),
}
gc.RegisterStaticMember(group, member) // Should be no-op
foundMember := gc.FindStaticMember(group, "")
if foundMember != nil {
t.Error("Expected not to find member with empty instance ID")
}
// Test empty string instance ID
emptyInstanceID := ""
member.GroupInstanceID = &emptyInstanceID
gc.RegisterStaticMember(group, member) // Should be no-op
foundMember = gc.FindStaticMember(group, emptyInstanceID)
if foundMember != nil {
t.Error("Expected not to find member with empty string instance ID")
}
// Test unregistering non-existent instance ID
gc.UnregisterStaticMember(group, "non-existent") // Should be no-op
}
func TestGroupCoordinator_StaticMembershipConcurrency(t *testing.T) {
gc := NewGroupCoordinator()
defer gc.Close()
group := gc.GetOrCreateGroup("test-group")
instanceID := "static-instance-1"
// Test concurrent access
done := make(chan bool, 2)
// Goroutine 1: Register static member
go func() {
member := &GroupMember{
ID: "member-1",
ClientID: "client-1",
ClientHost: "localhost",
GroupInstanceID: &instanceID,
SessionTimeout: 30000,
State: MemberStatePending,
LastHeartbeat: time.Now(),
JoinedAt: time.Now(),
}
group.Members[member.ID] = member
gc.RegisterStaticMember(group, member)
done <- true
}()
// Goroutine 2: Find static member
go func() {
time.Sleep(10 * time.Millisecond) // Small delay to ensure registration happens first
foundMember := gc.FindStaticMember(group, instanceID)
if foundMember == nil {
t.Error("Expected to find static member in concurrent access")
}
done <- true
}()
// Wait for both goroutines to complete
<-done
<-done
}