[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [pluggable-transports/meek] 06/09: Add TestCloseHaltsRequestLoop.



This is an automated email from the git hooks/post-receive script.

dcf pushed a commit to branch turbotunnel
in repository pluggable-transports/meek.

commit 4c76264472b5071b48dfa44c8273eb13fddbaedb
Author: David Fifield <david@xxxxxxxxxxxxxxx>
AuthorDate: Thu Oct 27 23:50:19 2022 -0600

    Add TestCloseHaltsRequestLoop.
---
 meek-client/turbotunnel_test.go | 57 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/meek-client/turbotunnel_test.go b/meek-client/turbotunnel_test.go
new file mode 100644
index 0000000..11640ec
--- /dev/null
+++ b/meek-client/turbotunnel_test.go
@@ -0,0 +1,57 @@
+package main
+
+import (
+	"bytes"
+	"errors"
+	"io"
+	"io/ioutil"
+	"testing"
+	"time"
+)
+
+type emptyAddr struct{}
+
+func (_ emptyAddr) Network() string { return "empty" }
+func (_ emptyAddr) String() string  { return "empty" }
+
+type funcPoller struct {
+	poll func(out io.Reader) (in io.ReadCloser, err error)
+}
+
+func (fp funcPoller) Poll(out io.Reader) (in io.ReadCloser, err error) {
+	return fp.poll(out)
+}
+
+// TestCloseHaltsRequestLoop tests that requestLoop terminates and stops calling
+// its Poller after Close is called.
+func TestCloseHaltsRequestLoop(t *testing.T) {
+	closedCh := make(chan struct{})
+	resultCh := make(chan error)
+	// The poller returns immediately with a nil error as long as closedCh
+	// is not closed. When closedCh is closed, the poller returns
+	// immediately with a non-nil error.
+	poller := funcPoller{poll: func(_ io.Reader) (io.ReadCloser, error) {
+		select {
+		case <-closedCh:
+			resultCh <- errors.New("poll called after close")
+		default:
+		}
+		return ioutil.NopCloser(bytes.NewReader(nil)), nil
+	}}
+	pconn := NewPollingPacketConn(emptyAddr{}, poller)
+	// Close the connection.
+	err := pconn.Close()
+	if err != nil {
+		t.Fatal(err)
+	}
+	// Tell the poll function to return an error if it is called after this
+	// point.
+	close(closedCh)
+	// Wait a few seconds to see if the poll function is called after the
+	// conn is closed.
+	select {
+	case err := <-resultCh:
+		t.Fatal(err)
+	case <-time.After(3 * time.Second):
+	}
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits