[tor-commits] [snowflake/main] Add unit tests to check for webrtc peer data races

cohosh at torproject.org cohosh at torproject.org
Thu Jun 24 15:56:19 UTC 2021


commit 95cbe36565d65bf1512acd0faeab9a1e2580808f
Author: Cecylia Bocovich <cohosh at torproject.org>
Date:   Thu Jun 17 17:43:40 2021 -0400

    Add unit tests to check for webrtc peer data races
---
 client/lib/lib_test.go | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/client/lib/lib_test.go b/client/lib/lib_test.go
index 55ea7b9..1eef0c0 100644
--- a/client/lib/lib_test.go
+++ b/client/lib/lib_test.go
@@ -7,6 +7,7 @@ import (
 	"net"
 	"net/http"
 	"testing"
+	"time"
 
 	"git.torproject.org/pluggable-transports/snowflake.git/common/util"
 	. "github.com/smartystreets/goconvey/convey"
@@ -154,6 +155,25 @@ func TestSnowflakeClient(t *testing.T) {
 			So(r, ShouldEqual, wc4)
 		})
 
+		Convey("Terminate Connect() loop", func() {
+			p, _ := NewPeers(FakeDialer{max: 4})
+			go func() {
+				for {
+					p.Collect()
+					select {
+					case <-p.Melted():
+						return
+					default:
+					}
+				}
+			}()
+			<-time.After(10 * time.Second)
+
+			p.End()
+			<-p.Melted()
+			So(p.Count(), ShouldEqual, 0)
+		})
+
 	})
 
 	Convey("Dialers", t, func() {
@@ -245,6 +265,17 @@ func TestSnowflakeClient(t *testing.T) {
 
 }
 
+func TestWebRTCPeer(t *testing.T) {
+	Convey("WebRTCPeer", t, func(c C) {
+		p := &WebRTCPeer{closed: make(chan struct{})}
+		Convey("checks for staleness", func() {
+			go p.checkForStaleness()
+			<-time.After(2 * SnowflakeTimeout)
+			So(p.Closed(), ShouldEqual, true)
+		})
+	})
+}
+
 func TestICEServerParser(t *testing.T) {
 	Convey("Test parsing of ICE servers", t, func() {
 		for _, test := range []struct {





More information about the tor-commits mailing list