Skip to content

Commit

Permalink
Fix #114 (#115)
Browse files Browse the repository at this point in the history
Fix #114

* Fixed test
  • Loading branch information
aandryashin authored and vania-pooh committed Sep 8, 2017
1 parent 269fcdd commit c89a024
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config.go
Expand Up @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions config_test.go
Expand Up @@ -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},
}},
}},
}}}}
Expand Down Expand Up @@ -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"})
Expand Down
Binary file removed docs/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion proxy.go
Expand Up @@ -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)
}
Expand Down
47 changes: 47 additions & 0 deletions proxy_test.go
Expand Up @@ -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) {
Expand Down

0 comments on commit c89a024

Please sign in to comment.