Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Fix #24 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
aandryashin authored and vania-pooh committed Jun 2, 2018
1 parent 5634321 commit 9320198
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
26 changes: 15 additions & 11 deletions ggr-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,25 @@ func mux() http.Handler {
return mux
}

type result struct {
sum string
status Status
}

func status(w http.ResponseWriter, r *http.Request) {
lock.RLock()
defer lock.RUnlock()
_, remote := util.RequestInfo(r)
ch := make(chan struct{}, limit)
rslt := make(chan Status)
rslt := make(chan *result)
done := make(chan Status)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func(ctx context.Context) {
for _, u := range hosts {
for sum, u := range hosts {
select {
case ch <- struct{}{}:
go func(ctx context.Context, u string) {
go func(ctx context.Context, sum, u string) {
defer func() {
<-ch
}()
Expand All @@ -80,8 +85,8 @@ func status(w http.ResponseWriter, r *http.Request) {
log.Printf("[STATUS] [Failed to parse response: %v] [%s]", err, remote)
return
}
rslt <- m
}(ctx, u)
rslt <- &result{sum, m}
}(ctx, sum, u)
case <-ctx.Done():
return
}
Expand All @@ -90,11 +95,11 @@ func status(w http.ResponseWriter, r *http.Request) {
go func(ctx context.Context) {
s := make(Status)
loop:
for sum, _ := range hosts {
for i := 0; i < len(hosts); i++ {
select {
case m := <-rslt:
if m != nil {
s.Add(sum, m)
case result := <-rslt:
if result != nil && result.status != nil {
s.Add(result.sum, result.status)
}
case <-time.After(responseTime):
break loop
Expand All @@ -105,11 +110,10 @@ func status(w http.ResponseWriter, r *http.Request) {
done <- s
}(ctx)
select {
case <-w.(http.CloseNotifier).CloseNotify():
cancel()
case s := <-done:
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(s)
case <-w.(http.CloseNotifier).CloseNotify():
}
}

Expand Down
34 changes: 34 additions & 0 deletions quota/browsers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<qa:browsers xmlns:qa="urn:config.gridrouter.qatools.ru">
<browser name="firefox" defaultVersion="60.0">
<version number="60.0">
<region name="1">
<host name="localhost" port="5555" count="5"/>
<host name="localhost" port="5556" count="5"/>
<host name="localhost" port="5557" count="5"/>
<host name="localhost" port="5558" count="5"/>
</region>
<region name="2">
<host name="localhost" port="5555" count="5"/>
<host name="localhost" port="5556" count="5"/>
<host name="localhost" port="5557" count="5"/>
<host name="localhost" port="5558" count="5"/>
</region>
</version>
</browser>
<browser name="chrome" defaultVersion="66.0">
<version number="66.0">
<region name="1">
<host name="localhost" port="5555" count="5"/>
<host name="localhost" port="5556" count="5"/>
<host name="localhost" port="5557" count="5"/>
<host name="localhost" port="5558" count="5"/>
</region>
<region name="2">
<host name="localhost" port="5555" count="5"/>
<host name="localhost" port="5556" count="5"/>
<host name="localhost" port="5557" count="5"/>
<host name="localhost" port="5558" count="5"/>
</region>
</version>
</browser>
</qa:browsers>
9 changes: 0 additions & 9 deletions quota/test.xml

This file was deleted.

0 comments on commit 9320198

Please sign in to comment.