feat: add dual-host IM pressure test tool
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNewManifestDistributesUsersAndEndpoints(t *testing.T) {
|
||||
cfg := &Config{Tenant: "006", UsersPerMachine: 3, Endpoints: map[string][]string{
|
||||
"a": {"ws://a1", "ws://a2"}, "b": {"ws://b1"},
|
||||
}}
|
||||
manifest := newManifest(cfg)
|
||||
if len(manifest.Accounts) != 6 {
|
||||
t.Fatalf("accounts=%d", len(manifest.Accounts))
|
||||
}
|
||||
if got := accountsForMachine(manifest, "a"); got[0].Username != "lta0001" || got[1].Endpoint != "ws://a2" || got[2].Endpoint != "ws://a1" {
|
||||
t.Fatalf("unexpected A accounts: %+v", got)
|
||||
}
|
||||
if err := manifest.validate(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManifestRejectsDuplicateAccount(t *testing.T) {
|
||||
manifest := &Manifest{Version: manifestVersion, Accounts: []AccountRecord{
|
||||
{Machine: "a", Index: 1, Username: "lta0001"},
|
||||
{Machine: "a", Index: 1, Username: "duplicate"},
|
||||
}}
|
||||
if err := manifest.validate(); err == nil {
|
||||
t.Fatal("expected duplicate account validation error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyConfigEndpointsRefreshesManifest(t *testing.T) {
|
||||
cfg := &Config{Tenant: "006", UsersPerMachine: 1, Endpoints: map[string][]string{
|
||||
"a": {"ws://new-a"}, "b": {"ws://new-b"},
|
||||
}}
|
||||
manifest := &Manifest{Tenant: "006", Accounts: []AccountRecord{
|
||||
{Machine: "a", Index: 1, Username: "lta0001", Endpoint: "ws://old"},
|
||||
{Machine: "b", Index: 1, Username: "ltb0001", Endpoint: "ws://old"},
|
||||
}}
|
||||
if err := applyConfigEndpoints(cfg, manifest); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if manifest.Accounts[0].Endpoint != "ws://new-a" || manifest.Accounts[1].Endpoint != "ws://new-b" {
|
||||
t.Fatalf("endpoints were not refreshed: %+v", manifest.Accounts)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user