~emersion/soju-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH RFC] Add basic backlog test

Details
Message ID
<20220110165500.155599-1-contact@emersion.fr>
DKIM signature
pass
Download raw message
Patch: +54 -4
---

Note, this test fails right now.

 server_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 54 insertions(+), 4 deletions(-)

diff --git a/server_test.go b/server_test.go
index b163e0e66fa6..40563aee1b0c 100644
--- a/server_test.go
+++ b/server_test.go
@@ -151,7 +151,7 @@ func registerUpstreamConn(t *testing.T, c ircConn) {
	})
}

func testServer(t *testing.T, db Database) {
func testServerNotice(t *testing.T, db Database) {
	user := createTestUser(t, db)
	network, upstream := createTestUpstream(t, db, user)
	defer upstream.Close()
@@ -194,14 +194,64 @@ func testServer(t *testing.T, db Database) {
	}
}

func TestServer(t *testing.T) {
func TestServerNotice(t *testing.T) {
	t.Run("sqlite", func(t *testing.T) {
		db := createTempSqliteDB(t)
		testServer(t, db)
		testServerNotice(t, db)
	})

	t.Run("postgres", func(t *testing.T) {
		db := createTempPostgresDB(t)
		testServer(t, db)
		testServerNotice(t, db)
	})
}

func TestServerBacklog(t *testing.T) {
	db := createTempSqliteDB(t)
	user := createTestUser(t, db)
	network, upstream := createTestUpstream(t, db, user)
	defer upstream.Close()

	srv := NewServer(db)
	if err := srv.Start(); err != nil {
		t.Fatalf("failed to start server: %v", err)
	}
	defer srv.Shutdown()

	uc := mustAccept(t, upstream)
	defer uc.Close()
	registerUpstreamConn(t, uc)

	// Create a new downstream connection and immediately close it
	dc := createTestDownstream(t, srv)
	registerDownstreamConn(t, dc, network)
	dc.Close()

	privmsgText := "This is a very important message."
	uc.WriteMessage(&irc.Message{
		Prefix:  &irc.Prefix{Name: "cool-user"},
		Command: "PRIVMSG",
		Params:  []string{testUsername, privmsgText},
	})

	// Re-create the downstream connection, wait for backlog
	dc = createTestDownstream(t, srv)
	registerDownstreamConn(t, dc, network)
	defer dc.Close()

	var msg *irc.Message
	for {
		var err error
		msg, err = dc.ReadMessage()
		if err != nil {
			t.Fatalf("failed to read IRC message: %v", err)
		}
		if msg.Command == "PRIVMSG" {
			break
		}
	}

	if msg.Params[1] != privmsgText {
		t.Fatalf("invalid PRIVMSG text: want %q, got: %v", privmsgText, msg)
	}
}
-- 
2.34.1
Reply to thread Export thread (mbox)