From 7f9250960b0060bf4ab979b898a1c5a0b8c2b7f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 31 Mar 2024 19:49:57 +0200 Subject: [PATCH] testing: Make the tests less flakey --- README.md | 4 +++- client_test.go | 7 +++++++ examples/servers/typed/main.go | 16 ---------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 395ed71..24df633 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,8 @@ func main() { receipt.Size = uint32(123) // Close the message stream. + // Pass true to drop any queued messages, + // this is only relevant if DelayDelivery is enabled. c.Close(false, receipt) }, }, @@ -152,7 +154,7 @@ The server can generate an ETag for the messages. This is a hash of all message To enable this: 1. Provide a `GetHasher` function to the [server options](https://pkg.go.dev/github.com/bep/execrpc#ServerOptions). -2. Have the `Receipt` implement the [ETagger](https://pkg.go.dev/github.com/bep/execrpc#ETagger) interface. +2. Have the `Receipt` implement the [TagProvider](https://pkg.go.dev/github.com/bep/execrpc#TagProvider) interface. Note that there are three different optional E-interfaces for the `Receipt`: diff --git a/client_test.go b/client_test.go index 260abe5..dffcd99 100644 --- a/client_test.go +++ b/client_test.go @@ -117,6 +117,8 @@ func TestExecTyped(t *testing.T) { assertMessages(c, result, 1) receipt := <-result.Receipt() c.Assert(receipt.GetESize(), qt.Equals, uint32(123)) + c.Assert(receipt.ETag, qt.Equals, "2d5537627636b58a") + c.Assert(receipt.Text, qt.Equals, "echoed: world") }) c.Run("100 messages", func(c *qt.C) { @@ -126,6 +128,7 @@ func TestExecTyped(t *testing.T) { receipt := <-result.Receipt() c.Assert(receipt.LastModified, qt.Not(qt.Equals), int64(0)) c.Assert(receipt.ETag, qt.Equals, "15b8164b761923b7") + c.Assert(receipt.Text, qt.Equals, "echoed: world") }) c.Run("1234 messages", func(c *qt.C) { @@ -136,6 +139,7 @@ func TestExecTyped(t *testing.T) { c.Assert(result.Err(), qt.IsNil) c.Assert(receipt.LastModified, qt.Not(qt.Equals), int64(0)) c.Assert(receipt.ETag, qt.Equals, "43940b97841cc686") + c.Assert(receipt.Text, qt.Equals, "echoed: world") }) c.Run("Delay delivery", func(c *qt.C) { @@ -144,6 +148,7 @@ func TestExecTyped(t *testing.T) { assertMessages(c, result, 1) receipt := <-result.Receipt() c.Assert(receipt.GetESize(), qt.Equals, uint32(123)) + c.Assert(receipt.Text, qt.Equals, "echoed: world") }) c.Run("Delay delivery, drop messages", func(c *qt.C) { @@ -154,6 +159,8 @@ func TestExecTyped(t *testing.T) { // This is a little confusing. We always get a receipt even if the messages are dropped, // and the server can create whatever protocol it wants. c.Assert(receipt.GetESize(), qt.Equals, uint32(123)) + c.Assert(receipt.ETag, qt.Equals, "2d5537627636b58a") + c.Assert(receipt.Text, qt.Equals, "echoed: world") }) c.Run("No Close", func(c *qt.C) { diff --git a/examples/servers/typed/main.go b/examples/servers/typed/main.go index 594d2bc..813e3b8 100644 --- a/examples/servers/typed/main.go +++ b/examples/servers/typed/main.go @@ -7,8 +7,6 @@ import ( "log" "os" "strconv" - "sync/atomic" - "time" "github.com/bep/execrpc" "github.com/bep/execrpc/examples/model" @@ -101,23 +99,9 @@ func main() { if !noClose { var receipt model.ExampleReceipt if !noReadingReceipt { - var receiptSeen atomic.Bool - go func() { - time.Sleep(1 * time.Second) - if !receiptSeen.Load() { - log.Fatalf("expected receipt to be seen") - } - }() - receipt = <-c.Receipt() receipt.Text = "echoed: " + c.Request.Text receipt.Size = uint32(123) - - receiptSeen.Store(true) - - if getHasher != nil && receipt.ETag == "" { - log.Fatalf("expected receipt eTag to be set") - } } c.Close(dropMessages, receipt)