mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 22:56:48 +00:00
Other: Fix goroutine leaks in sync tests
Add missing Close calls. Properly handle nil channel for `user.startSync`. This patch also updated liteapi and Gluon to latest master and dev version respectively.
This commit is contained in:
committed by
James Houlahan
parent
6fdc8bd379
commit
6bbaf03f1f
@ -93,6 +93,8 @@ type Bridge struct {
|
||||
|
||||
// stopCh is used to stop ongoing goroutines when the bridge is closed.
|
||||
stopCh chan struct{}
|
||||
|
||||
closeEventChFn func()
|
||||
}
|
||||
|
||||
// New creates a new bridge.
|
||||
@ -165,7 +167,9 @@ func New( //nolint:funlen
|
||||
)
|
||||
|
||||
// Get an event channel for all events (individual events can be subscribed to later).
|
||||
eventCh, _ := bridge.GetEvents()
|
||||
eventCh, closeFn := bridge.GetEvents()
|
||||
|
||||
bridge.closeEventChFn = closeFn
|
||||
|
||||
if err := bridge.init(tlsReporter); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to initialize bridge: %w", err)
|
||||
@ -303,6 +307,14 @@ func (bridge *Bridge) GetErrors() []error {
|
||||
}
|
||||
|
||||
func (bridge *Bridge) Close(ctx context.Context) error {
|
||||
defer func() {
|
||||
if bridge.closeEventChFn != nil {
|
||||
bridge.closeEventChFn()
|
||||
}
|
||||
|
||||
bridge.closeEventChFn = nil
|
||||
}()
|
||||
|
||||
// Stop ongoing operations such as connectivity checks.
|
||||
close(bridge.stopCh)
|
||||
|
||||
@ -356,6 +368,7 @@ func (bridge *Bridge) addWatcher(ofType ...events.Event) *watcher.Watcher[events
|
||||
}
|
||||
|
||||
func (bridge *Bridge) remWatcher(oldWatcher *watcher.Watcher[events.Event]) {
|
||||
oldWatcher.Close()
|
||||
bridge.watchers.Delete(oldWatcher)
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,8 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/events"
|
||||
"github.com/bradenaw/juniper/iterator"
|
||||
@ -36,6 +38,8 @@ import (
|
||||
)
|
||||
|
||||
func TestBridge_Sync(t *testing.T) {
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreCurrent())
|
||||
|
||||
s := server.New()
|
||||
defer s.Close()
|
||||
|
||||
@ -56,6 +60,7 @@ func TestBridge_Sync(t *testing.T) {
|
||||
liteapi.WithTransport(liteapi.InsecureTransport()),
|
||||
).NewClientWithLogin(ctx, "imap", password)
|
||||
require.NoError(t, err)
|
||||
defer c.Close()
|
||||
|
||||
user, err := c.GetUser(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -394,6 +394,9 @@ func (bridge *Bridge) addUserWithVault(
|
||||
return fmt.Errorf("failed to create user: %w", err)
|
||||
}
|
||||
|
||||
if bridge.users.Has(apiUser.ID) {
|
||||
panic("double add")
|
||||
}
|
||||
bridge.users.Set(apiUser.ID, user)
|
||||
|
||||
// Connect the user's address(es) to gluon.
|
||||
|
||||
Reference in New Issue
Block a user