fix front end issues
This commit is contained in:
parent
177cf45af5
commit
d7afd72e5b
18 changed files with 345 additions and 61 deletions
|
|
@ -11,31 +11,39 @@ func resetStores() {
|
|||
store.InitStores()
|
||||
}
|
||||
|
||||
func TestOnHostConfigUpdated_NewHost(t *testing.T) {
|
||||
func TestOnHostConfigUpdated_UnregisteredHostIgnored(t *testing.T) {
|
||||
// Config-only entries (e.g. "default", hosts whose daemons haven't started)
|
||||
// must not be inserted into the Hosts store. Only OnHostUpdated (worker push) creates entries.
|
||||
resetStores()
|
||||
h := DefaultHandler{}
|
||||
|
||||
host := &models.HostInfo{
|
||||
h.OnHostConfigUpdated(&models.HostInfo{
|
||||
HostName: "node01",
|
||||
HostModel: "x86_64",
|
||||
HostType: "LINUX64",
|
||||
MaxSlot: 8,
|
||||
}
|
||||
})
|
||||
|
||||
h.OnHostConfigUpdated(host)
|
||||
_, ok := store.Hosts.Get("node01")
|
||||
if ok {
|
||||
t.Error("OnHostConfigUpdated must not create a new host entry; only workers can register hosts")
|
||||
}
|
||||
}
|
||||
|
||||
got, ok := store.Hosts.Get("node01")
|
||||
if !ok {
|
||||
t.Fatal("host node01 should exist in store after OnHostConfigUpdated")
|
||||
}
|
||||
if got.HostModel != "x86_64" {
|
||||
t.Errorf("HostModel: got %q, want %q", got.HostModel, "x86_64")
|
||||
}
|
||||
if got.HostType != "LINUX64" {
|
||||
t.Errorf("HostType: got %q, want %q", got.HostType, "LINUX64")
|
||||
}
|
||||
if got.MaxSlot != 8 {
|
||||
t.Errorf("MaxSlot: got %d, want 8", got.MaxSlot)
|
||||
func TestOnHostConfigUpdated_DefaultPseudoHostIgnored(t *testing.T) {
|
||||
// The "default" host is a cluster-wide config sentinel, never a real worker.
|
||||
resetStores()
|
||||
h := DefaultHandler{}
|
||||
|
||||
h.OnHostConfigUpdated(&models.HostInfo{
|
||||
HostName: "default",
|
||||
HostType: "x86_64-linux-gnu",
|
||||
MaxSlot: -1,
|
||||
})
|
||||
|
||||
_, ok := store.Hosts.Get("default")
|
||||
if ok {
|
||||
t.Error("OnHostConfigUpdated must not create an entry for the 'default' pseudo-host")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -249,20 +257,27 @@ func TestOnHostUpdated_NewHost(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDispatchConfigPush_CallsOnHostConfigUpdatedForEachHost(t *testing.T) {
|
||||
func TestDispatchConfigPush_MergesConfigOntoRegisteredHosts(t *testing.T) {
|
||||
// Config push should merge onto hosts already registered by workers, and
|
||||
// silently skip any host not yet in the store (e.g. "default", offline workers).
|
||||
resetStores()
|
||||
h := &DefaultHandler{}
|
||||
|
||||
// Simulate worker registration arriving before config push.
|
||||
store.Hosts.Put("node01", models.HostInfo{HostName: "node01", NumCPUs: 32})
|
||||
store.Hosts.Put("node02", models.HostInfo{HostName: "node02", NumCPUs: 64})
|
||||
|
||||
hosts := []models.HostInfo{
|
||||
{HostName: "node01", HostModel: "x86_64", HostType: "LINUX64", MaxSlot: 4},
|
||||
{HostName: "node02", HostModel: "arm64", HostType: "LINUX64", MaxSlot: 8},
|
||||
{HostName: "default", HostModel: "x86_64", HostType: "LINUX64", MaxSlot: -1},
|
||||
}
|
||||
|
||||
dispatchConfigPush(h, nil, nil, hosts, nil)
|
||||
|
||||
got1, ok1 := store.Hosts.Get("node01")
|
||||
if !ok1 {
|
||||
t.Fatal("node01 should be in store after dispatchConfigPush")
|
||||
t.Fatal("node01 should remain in store after dispatchConfigPush")
|
||||
}
|
||||
if got1.HostModel != "x86_64" {
|
||||
t.Errorf("node01 HostModel: got %q, want x86_64", got1.HostModel)
|
||||
|
|
@ -270,10 +285,13 @@ func TestDispatchConfigPush_CallsOnHostConfigUpdatedForEachHost(t *testing.T) {
|
|||
if got1.MaxSlot != 4 {
|
||||
t.Errorf("node01 MaxSlot: got %d, want 4", got1.MaxSlot)
|
||||
}
|
||||
if got1.NumCPUs != 32 {
|
||||
t.Errorf("node01 NumCPUs: got %d, want 32 (worker field must be preserved)", got1.NumCPUs)
|
||||
}
|
||||
|
||||
got2, ok2 := store.Hosts.Get("node02")
|
||||
if !ok2 {
|
||||
t.Fatal("node02 should be in store after dispatchConfigPush")
|
||||
t.Fatal("node02 should remain in store after dispatchConfigPush")
|
||||
}
|
||||
if got2.HostModel != "arm64" {
|
||||
t.Errorf("node02 HostModel: got %q, want arm64", got2.HostModel)
|
||||
|
|
@ -281,6 +299,13 @@ func TestDispatchConfigPush_CallsOnHostConfigUpdatedForEachHost(t *testing.T) {
|
|||
if got2.MaxSlot != 8 {
|
||||
t.Errorf("node02 MaxSlot: got %d, want 8", got2.MaxSlot)
|
||||
}
|
||||
|
||||
if _, ok := store.Hosts.Get("default"); ok {
|
||||
t.Error("'default' pseudo-host must not be inserted by config push")
|
||||
}
|
||||
if n := store.Hosts.Count(); n != 2 {
|
||||
t.Errorf("Hosts store should have exactly 2 entries, got %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatchConfigPush_CallsOnClusterUpdated(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue