]> git.r.bdr.sh - rbdr/mobius/commitdiff
Fix inconsistent sorting of user list
authorJeff Halter <redacted>
Thu, 26 May 2022 23:53:06 +0000 (16:53 -0700)
committerJeff Halter <redacted>
Thu, 26 May 2022 23:53:06 +0000 (16:53 -0700)
hotline/server.go
hotline/transaction_handlers_test.go

index 30121a6f1479432d3fdcac0ba55a6a2db135ee23..4e2bde2fdfcd613211620efc2980e65ba67fe1a9 100644 (file)
@@ -169,7 +169,7 @@ func (s *Server) Serve(ctx context.Context, cancelRoot context.CancelFunc, ln ne
 }
 
 const (
 }
 
 const (
-       agreementFile    = "Agreement.txt"
+       agreementFile = "Agreement.txt"
 )
 
 // NewServer constructs a new Server from a config dir
 )
 
 // 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
        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,
                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) {
 // 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) {
index 21643bfeddb9c367cf9d2bcdfb9401ed5946369e..56968a1e1f0b4e48797766e836964e83b5716cb5 100644 (file)
@@ -228,6 +228,12 @@ func TestHandleGetUserNameList(t *testing.T) {
                                                                Flags:    &[]byte{0, 3},
                                                                UserName: []byte{0, 4},
                                                        },
                                                                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},
                                                ),
                                                        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},
+                                               ),
                                        },
                                },
                        },
                                        },
                                },
                        },