From: Jeff Halter Date: Thu, 26 May 2022 23:53:06 +0000 (-0700) Subject: Fix inconsistent sorting of user list X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/c7e932c079c1881aed346d4f6f734c3f401bd637?ds=inline Fix inconsistent sorting of user list --- diff --git a/hotline/server.go b/hotline/server.go index 30121a6..4e2bde2 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -169,7 +169,7 @@ func (s *Server) Serve(ctx context.Context, cancelRoot context.CancelFunc, ln ne } const ( - agreementFile = "Agreement.txt" + agreementFile = "Agreement.txt" ) // NewServer constructs a new Server from a config dir @@ -377,7 +377,7 @@ func (s *Server) connectedUsers() []Field { defer s.mux.Unlock() var connectedUsers []Field - for _, c := range s.Clients { + for _, c := range sortedClients(s.Clients) { user := User{ ID: *c.ID, Icon: *c.Icon, @@ -993,7 +993,6 @@ func transferFile(conn net.Conn, dst string) error { } } - // sortedClients is a utility function that takes a map of *ClientConn and returns a sorted slice of the values. // The purpose of this is to ensure that the ordering of client connections is deterministic so that test assertions work. func sortedClients(unsortedClients map[uint16]*ClientConn) (clients []*ClientConn) { diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index 21643bf..56968a1 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -228,6 +228,12 @@ func TestHandleGetUserNameList(t *testing.T) { Flags: &[]byte{0, 3}, UserName: []byte{0, 4}, }, + uint16(2): { + ID: &[]byte{0, 2}, + Icon: &[]byte{0, 2}, + Flags: &[]byte{0, 3}, + UserName: []byte{0, 4}, + }, }, }, }, @@ -249,6 +255,10 @@ func TestHandleGetUserNameList(t *testing.T) { fieldUsernameWithInfo, []byte{00, 01, 00, 02, 00, 03, 00, 02, 00, 04}, ), + NewField( + fieldUsernameWithInfo, + []byte{00, 02, 00, 02, 00, 03, 00, 02, 00, 04}, + ), }, }, },