diff --git a/config.go b/config.go index 0b9ad6d..e2cba19 100644 --- a/config.go +++ b/config.go @@ -116,7 +116,7 @@ func (b *Browsers) find(browser, version string, excludedHosts set, excludedRegi continue next } for _, h := range r.Hosts { - if !excludedHosts.contains(h.Name) { + if !excludedHosts.contains(h.net()) { hosts = append(hosts, h) } } diff --git a/config_test.go b/config_test.go index ff0370e..8696977 100644 --- a/config_test.go +++ b/config_test.go @@ -63,10 +63,10 @@ var ( {Name: "browser", DefaultVersion: "1.0", Versions: []Version{ {Number: "1.0", Regions: []Region{ {Name: "e", Hosts: Hosts{ - Host{Name: "browser-e-1.0"}, + Host{Name: "browser-e-1.0", Port: 4444}, }}, {Name: "f", Hosts: Hosts{ - Host{Name: "browser-f-1.0"}, + Host{Name: "browser-f-1.0", Port: 4444}, }}, }}, }}}} @@ -113,7 +113,7 @@ func TestFindWithExcludedRegionsExhausted(t *testing.T) { } func TestFindWithExcludedHosts(t *testing.T) { - hosts, version, _ := browsersWithMultipleRegions.find("browser", "1.0", newSet("browser-e-1.0"), newSet()) + hosts, version, _ := browsersWithMultipleRegions.find("browser", "1.0", newSet("browser-e-1.0:4444"), newSet()) AssertThat(t, version, EqualTo{"1.0"}) AssertThat(t, len(hosts), EqualTo{1}) AssertThat(t, hosts[0].Name, EqualTo{"browser-f-1.0"}) diff --git a/docs/.DS_Store b/docs/.DS_Store deleted file mode 100644 index ae216f6..0000000 Binary files a/docs/.DS_Store and /dev/null differ diff --git a/proxy.go b/proxy.go index 8b91520..14af8f7 100644 --- a/proxy.go +++ b/proxy.go @@ -265,7 +265,7 @@ loop: case browserFailed: hosts = append(hosts[:i], hosts[i+1:]...) case seleniumError: - excludedHosts.add(h.Name) + excludedHosts.add(h.net()) excludedRegions.add(h.region) hosts, version, excludedRegions = browsers.find(browser, version, excludedHosts, excludedRegions) } diff --git a/proxy_test.go b/proxy_test.go index 3ff6398..c571467 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -542,6 +542,53 @@ func TestStartSessionFail(t *testing.T) { AssertThat(t, rsp, AllOf{Code{http.StatusInternalServerError}, Message{"cannot create session browser-1.0 on any hosts after 1 attempt(s)"}}) } +func TestStartSessionFailMultiRegion(t *testing.T) { + node := []Host{ + Host{Name: "localhost", Port: 9991, Count: 1}, + Host{Name: "localhost", Port: 9992, Count: 1}, + Host{Name: "localhost", Port: 9993, Count: 1}, + Host{Name: "localhost", Port: 9994, Count: 1}, + Host{Name: "localhost", Port: 9995, Count: 1}, + Host{Name: "localhost", Port: 9996, Count: 1}, + Host{Name: "localhost", Port: 9997, Count: 1}, + Host{Name: "localhost", Port: 9998, Count: 1}, + Host{Name: "localhost", Port: 9999, Count: 1}, + } + + test.Lock() + defer test.Unlock() + + browsers := Browsers{Browsers: []Browser{ + {Name: "browser", DefaultVersion: "1.0", Versions: []Version{ + {Number: "1.0", Regions: []Region{ + Region{ + Name: "us-west-1", + Hosts: Hosts{ + node[0], node[1], node[2], + }, + }, + Region{ + Name: "us-west-2", + Hosts: Hosts{ + node[3], node[4], node[5], + }, + }, + Region{ + Name: "us-west-3", + Hosts: Hosts{ + node[6], node[7], node[8], + }, + }, + }}, + }}}} + updateQuota(user, browsers) + + rsp, err := createSession(`{"desiredCapabilities":{"browserName":"browser", "version":"1.0"}}`) + + AssertThat(t, err, Is{nil}) + AssertThat(t, rsp, AllOf{Code{http.StatusInternalServerError}, Message{"cannot create session browser-1.0 on any hosts after 9 attempt(s)"}}) +} + func TestStartSessionBrowserFail(t *testing.T) { mux := http.NewServeMux() mux.HandleFunc("/wd/hub/session", postOnly(func(w http.ResponseWriter, r *http.Request) {