Skip to content

Commit

Permalink
Update go.sum|mod, add the start of a chat-server test
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanfetch committed Jul 21, 2023
1 parent 499a64e commit 1dd0f1a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
46 changes: 46 additions & 0 deletions chatserver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package chatserver_test

import (
"bufio"
"net"
"testing"
"time"

"github.com/ivanfetch/chatserver"
)

func TestChatSession(t *testing.T) {
t.Parallel()
finishByTime := time.After(5 * time.Second)
done := make(chan bool)
go func() {
t.Log("starting chat server")
server, err := chatserver.RunWithoutWaitingForExit()
if err != nil {
t.Fatal(err)
}
client1, err := net.Dial("tcp", server.GetListenAddress())
if err != nil {
t.Fatalf("client 1 cannot connect to chat server: %v", err)
}
client1Reader := bufio.NewReader(client1)
client1Str, err := client1Reader.ReadString('\n')
if err != nil {
t.Fatalf("client 1 cannot read a string from its chat-server connection: %v", err)
}
t.Logf("client 1 read from chat server: %s\n", client1Str)
time.Sleep(15 * time.Second) // don't shutdown the server while we're using it
t.Log("stopping chat server")
server.InitiateShutdown()
t.Log("Waiting for shutdown\n")
server.WaitForExit()
return
done <- true
}()

select {
case <-timeout:
t.Fatalf("Test didn't finish in time %s", timeoutDuration.String())
case <-done:
}
}
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module github.com/ivanfetch/chatserver

go 1.20

require (
github.com/sirupsen/logrus v1.9.2 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
)
require github.com/sirupsen/logrus v1.9.2

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 1dd0f1a

Please sign in to comment.