mirror of
https://github.com/mochi-mqtt/server.git
synced 2025-11-02 12:24:05 +08:00
Replace DefaultServerCapabilities with NewDefaultServerCapabilities() to avoid data race (#360)
Co-authored-by: JB <28275108+mochi-co@users.noreply.github.com>
This commit is contained in:
@@ -96,24 +96,24 @@ func (h *DelayHook) OnDisconnect(cl *Client, err error, expire bool) {
|
||||
}
|
||||
|
||||
func newServer() *Server {
|
||||
cc := *DefaultServerCapabilities
|
||||
cc := NewDefaultServerCapabilities()
|
||||
cc.MaximumMessageExpiryInterval = 0
|
||||
cc.ReceiveMaximum = 0
|
||||
s := New(&Options{
|
||||
Logger: logger,
|
||||
Capabilities: &cc,
|
||||
Capabilities: cc,
|
||||
})
|
||||
_ = s.AddHook(new(AllowHook), nil)
|
||||
return s
|
||||
}
|
||||
|
||||
func newServerWithInlineClient() *Server {
|
||||
cc := *DefaultServerCapabilities
|
||||
cc := NewDefaultServerCapabilities()
|
||||
cc.MaximumMessageExpiryInterval = 0
|
||||
cc.ReceiveMaximum = 0
|
||||
s := New(&Options{
|
||||
Logger: logger,
|
||||
Capabilities: &cc,
|
||||
Capabilities: cc,
|
||||
InlineClient: true,
|
||||
})
|
||||
_ = s.AddHook(new(AllowHook), nil)
|
||||
@@ -125,7 +125,7 @@ func TestOptionsSetDefaults(t *testing.T) {
|
||||
opts.ensureDefaults()
|
||||
|
||||
require.Equal(t, defaultSysTopicInterval, opts.SysTopicResendInterval)
|
||||
require.Equal(t, DefaultServerCapabilities, opts.Capabilities)
|
||||
require.Equal(t, NewDefaultServerCapabilities(), opts.Capabilities)
|
||||
|
||||
opts = new(Options)
|
||||
opts.ensureDefaults()
|
||||
@@ -1529,10 +1529,10 @@ func TestServerProcessPublishACLCheckDeny(t *testing.T) {
|
||||
|
||||
for _, tx := range tt {
|
||||
t.Run(tx.name, func(t *testing.T) {
|
||||
cc := *DefaultServerCapabilities
|
||||
cc := NewDefaultServerCapabilities()
|
||||
s := New(&Options{
|
||||
Logger: logger,
|
||||
Capabilities: &cc,
|
||||
Capabilities: cc,
|
||||
})
|
||||
_ = s.AddHook(new(DenyHook), nil)
|
||||
_ = s.Serve()
|
||||
@@ -3131,22 +3131,22 @@ func TestServerLoadClients(t *testing.T) {
|
||||
{ID: "v3-clean", ProtocolVersion: 4, Clean: true},
|
||||
{ID: "v3-not-clean", ProtocolVersion: 4, Clean: false},
|
||||
{
|
||||
ID: "v5-clean",
|
||||
ID: "v5-clean",
|
||||
ProtocolVersion: 5,
|
||||
Clean: true,
|
||||
Clean: true,
|
||||
Properties: storage.ClientProperties{
|
||||
SessionExpiryInterval: 10,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "v5-expire-interval-0",
|
||||
ID: "v5-expire-interval-0",
|
||||
ProtocolVersion: 5,
|
||||
Properties: storage.ClientProperties{
|
||||
SessionExpiryInterval: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "v5-expire-interval-not-0",
|
||||
ID: "v5-expire-interval-not-0",
|
||||
ProtocolVersion: 5,
|
||||
Properties: storage.ClientProperties{
|
||||
SessionExpiryInterval: 10,
|
||||
|
||||
Reference in New Issue
Block a user