mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Fix race is broker test reported by go test -race
This commit is contained in:
parent
c3c84fdb48
commit
dfb68d7cfc
1 changed files with 15 additions and 12 deletions
|
@ -173,10 +173,10 @@ func TestBroker(t *testing.T) {
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
Convey("with a client offer if available.", func() {
|
Convey("with a client offer if available.", func() {
|
||||||
go func(ctx *BrokerContext) {
|
go func(i *IPC) {
|
||||||
proxyPolls(i, w, r)
|
proxyPolls(i, w, r)
|
||||||
done <- true
|
done <- true
|
||||||
}(ctx)
|
}(i)
|
||||||
// Pass a fake client offer to this proxy
|
// Pass a fake client offer to this proxy
|
||||||
p := <-ctx.proxyPolls
|
p := <-ctx.proxyPolls
|
||||||
So(p.id, ShouldEqual, "ymbcCMto7KHNGYlp")
|
So(p.id, ShouldEqual, "ymbcCMto7KHNGYlp")
|
||||||
|
@ -187,10 +187,10 @@ func TestBroker(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("return empty 200 OK when no client offer is available.", func() {
|
Convey("return empty 200 OK when no client offer is available.", func() {
|
||||||
go func(ctx *BrokerContext) {
|
go func(i *IPC) {
|
||||||
proxyPolls(i, w, r)
|
proxyPolls(i, w, r)
|
||||||
done <- true
|
done <- true
|
||||||
}(ctx)
|
}(i)
|
||||||
p := <-ctx.proxyPolls
|
p := <-ctx.proxyPolls
|
||||||
So(p.id, ShouldEqual, "ymbcCMto7KHNGYlp")
|
So(p.id, ShouldEqual, "ymbcCMto7KHNGYlp")
|
||||||
// nil means timeout
|
// nil means timeout
|
||||||
|
@ -202,6 +202,7 @@ func TestBroker(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Responds to proxy answers...", func() {
|
Convey("Responds to proxy answers...", func() {
|
||||||
|
done := make(chan bool)
|
||||||
s := ctx.AddSnowflake("test", "", NATUnrestricted, 0)
|
s := ctx.AddSnowflake("test", "", NATUnrestricted, 0)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
data := bytes.NewReader([]byte(`{"Version":"1.0","Sid":"test","Answer":"test"}`))
|
data := bytes.NewReader([]byte(`{"Version":"1.0","Sid":"test","Answer":"test"}`))
|
||||||
|
@ -209,10 +210,12 @@ func TestBroker(t *testing.T) {
|
||||||
Convey("by passing to the client if valid.", func() {
|
Convey("by passing to the client if valid.", func() {
|
||||||
r, err := http.NewRequest("POST", "snowflake.broker/answer", data)
|
r, err := http.NewRequest("POST", "snowflake.broker/answer", data)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
go func(ctx *BrokerContext) {
|
go func(i *IPC) {
|
||||||
proxyAnswers(i, w, r)
|
proxyAnswers(i, w, r)
|
||||||
}(ctx)
|
done <- true
|
||||||
|
}(i)
|
||||||
answer := <-s.answerChannel
|
answer := <-s.answerChannel
|
||||||
|
<-done
|
||||||
So(w.Code, ShouldEqual, http.StatusOK)
|
So(w.Code, ShouldEqual, http.StatusOK)
|
||||||
So(answer, ShouldResemble, "test")
|
So(answer, ShouldResemble, "test")
|
||||||
})
|
})
|
||||||
|
@ -265,10 +268,10 @@ func TestBroker(t *testing.T) {
|
||||||
rp, err := http.NewRequest("POST", "snowflake.broker/proxy", datap)
|
rp, err := http.NewRequest("POST", "snowflake.broker/proxy", datap)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
go func(ctx *BrokerContext) {
|
go func(i *IPC) {
|
||||||
proxyPolls(i, wp, rp)
|
proxyPolls(i, wp, rp)
|
||||||
proxy_done <- true
|
proxy_done <- true
|
||||||
}(ctx)
|
}(i)
|
||||||
|
|
||||||
// Client offer
|
// Client offer
|
||||||
wc := httptest.NewRecorder()
|
wc := httptest.NewRecorder()
|
||||||
|
@ -289,10 +292,10 @@ func TestBroker(t *testing.T) {
|
||||||
datap = bytes.NewReader([]byte(`{"Version":"1.0","Sid":"ymbcCMto7KHNGYlp","Answer":"test"}`))
|
datap = bytes.NewReader([]byte(`{"Version":"1.0","Sid":"ymbcCMto7KHNGYlp","Answer":"test"}`))
|
||||||
rp, err = http.NewRequest("POST", "snowflake.broker/answer", datap)
|
rp, err = http.NewRequest("POST", "snowflake.broker/answer", datap)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
go func(ctx *BrokerContext) {
|
go func(i *IPC) {
|
||||||
proxyAnswers(i, wp, rp)
|
proxyAnswers(i, wp, rp)
|
||||||
proxy_done <- true
|
proxy_done <- true
|
||||||
}(ctx)
|
}(i)
|
||||||
|
|
||||||
<-proxy_done
|
<-proxy_done
|
||||||
<-client_done
|
<-client_done
|
||||||
|
@ -682,10 +685,10 @@ func TestMetrics(t *testing.T) {
|
||||||
r, err := http.NewRequest("POST", "snowflake.broker/proxy", data)
|
r, err := http.NewRequest("POST", "snowflake.broker/proxy", data)
|
||||||
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
|
r.RemoteAddr = "129.97.208.23:8888" //CA geoip
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
go func(ctx *BrokerContext) {
|
go func(i *IPC) {
|
||||||
proxyPolls(i, w, r)
|
proxyPolls(i, w, r)
|
||||||
done <- true
|
done <- true
|
||||||
}(ctx)
|
}(i)
|
||||||
p := <-ctx.proxyPolls //manually unblock poll
|
p := <-ctx.proxyPolls //manually unblock poll
|
||||||
p.offerChannel <- nil
|
p.offerChannel <- nil
|
||||||
<-done
|
<-done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue