@@ -2025,6 +2025,59 @@ func TestConfigReloadMaxConnections(t *testing.T) {
20252025 }
20262026}
20272027
2028+ // Ensure Reload supports refusing all connections. Test this by starting a
2029+ // server with no max connections, connecting two clients, reloading with a
2030+ // max connections of one, and ensuring one client is disconnected.
2031+ func TestConfigReloadMaxConnectionsPreventAll (t * testing.T ) {
2032+ server , opts , config := runReloadServerWithConfig (t , "./configs/reload/basic.conf" )
2033+ defer server .Shutdown ()
2034+
2035+ // Make two connections.
2036+ addr := fmt .Sprintf ("nats://%s:%d" , opts .Host , server .Addr ().(* net.TCPAddr ).Port )
2037+ nc1 , err := nats .Connect (addr )
2038+ if err != nil {
2039+ t .Fatalf ("Error creating client: %v" , err )
2040+ }
2041+ defer nc1 .Close ()
2042+ closed := make (chan struct {}, 1 )
2043+ nc1 .SetDisconnectHandler (func (* nats.Conn ) {
2044+ closed <- struct {}{}
2045+ })
2046+ nc2 , err := nats .Connect (addr )
2047+ if err != nil {
2048+ t .Fatalf ("Error creating client: %v" , err )
2049+ }
2050+ defer nc2 .Close ()
2051+ nc2 .SetDisconnectHandler (func (* nats.Conn ) {
2052+ closed <- struct {}{}
2053+ })
2054+
2055+ if numClients := server .NumClients (); numClients != 2 {
2056+ t .Fatalf ("Expected 2 clients, got %d" , numClients )
2057+ }
2058+
2059+ // Set max connections to one.
2060+ changeCurrentConfigContent (t , config , "./configs/reload/max_connections_refuse_all.conf" )
2061+ if err := server .Reload (); err != nil {
2062+ t .Fatalf ("Error reloading config: %v" , err )
2063+ }
2064+
2065+ // Ensure one connection was closed.
2066+ select {
2067+ case <- closed :
2068+ case <- time .After (5 * time .Second ):
2069+ t .Fatal ("Expected to be disconnected" )
2070+ }
2071+
2072+ checkClientsCount (t , server , 0 )
2073+
2074+ // Ensure new connections fail.
2075+ _ , err = nats .Connect (addr )
2076+ if err == nil {
2077+ t .Fatal ("Expected error on connect" )
2078+ }
2079+ }
2080+
20282081// Ensure reload supports changing the max payload size. Test this by starting
20292082// a server with the default size limit, ensuring publishes work, reloading
20302083// with a restrictive limit, and ensuring publishing an oversized message fails
0 commit comments