mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Add tests to check for data race in broker
We had some data races in the broker that occur when proxies and clients modify the heap/snowflake map at the same time. This test has a client and proxy access the broker simultaneously to check for data races.
This commit is contained in:
parent
dccc15a6e9
commit
42e16021c4
1 changed files with 93 additions and 43 deletions
|
@ -191,12 +191,61 @@ func TestBroker(t *testing.T) {
|
|||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Convey("End-To-End", t, func() {
|
||||
ctx := NewBrokerContext(NullLogger())
|
||||
|
||||
Convey("Check for client/proxy data race", func() {
|
||||
proxy_done := make(chan bool)
|
||||
client_done := make(chan bool)
|
||||
|
||||
go ctx.Broker()
|
||||
|
||||
// Make proxy poll
|
||||
wp := httptest.NewRecorder()
|
||||
datap := bytes.NewReader([]byte(`{"Sid":"ymbcCMto7KHNGYlp","Version":"1.0"}`))
|
||||
rp, err := http.NewRequest("POST", "snowflake.broker/proxy", datap)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
go func(ctx *BrokerContext) {
|
||||
proxyPolls(ctx, wp, rp)
|
||||
proxy_done <- true
|
||||
}(ctx)
|
||||
|
||||
// Client offer
|
||||
wc := httptest.NewRecorder()
|
||||
datac := bytes.NewReader([]byte("test"))
|
||||
rc, err := http.NewRequest("POST", "snowflake.broker/client", datac)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
go func() {
|
||||
clientOffers(ctx, wc, rc)
|
||||
client_done <- true
|
||||
}()
|
||||
|
||||
<-proxy_done
|
||||
So(wp.Code, ShouldEqual, http.StatusOK)
|
||||
|
||||
// Proxy answers
|
||||
wp = httptest.NewRecorder()
|
||||
datap = bytes.NewReader([]byte(`{"Version":"1.0","Sid":"ymbcCMto7KHNGYlp","Answer":"test"}`))
|
||||
rp, err = http.NewRequest("POST", "snowflake.broker/answer", datap)
|
||||
So(err, ShouldBeNil)
|
||||
go func(ctx *BrokerContext) {
|
||||
proxyAnswers(ctx, wp, rp)
|
||||
proxy_done <- true
|
||||
}(ctx)
|
||||
|
||||
<-proxy_done
|
||||
<-client_done
|
||||
|
||||
})
|
||||
|
||||
Convey("Ensure correct snowflake brokering", func() {
|
||||
done := make(chan bool)
|
||||
polled := make(chan bool)
|
||||
ctx := NewBrokerContext(NullLogger())
|
||||
|
||||
// Proxy polls with its ID first...
|
||||
dataP := bytes.NewReader([]byte(`{"Sid":"ymbcCMto7KHNGYlp","Version":"1.0"}`))
|
||||
|
@ -244,6 +293,7 @@ func TestBroker(t *testing.T) {
|
|||
So(wC.Code, ShouldEqual, http.StatusOK)
|
||||
So(wC.Body.String(), ShouldEqual, "test")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestSnowflakeHeap(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue