mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-20 00:56:47 +00:00
GODT-1409 Wait in GetEvents during message preparation for live API.
This commit is contained in:
26
test/liveapi/events.go
Normal file
26
test/liveapi/events.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2021 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package liveapi
|
||||
|
||||
func (ctl *Controller) LockEvents() {
|
||||
persistentClients.eventsPaused.Add(1)
|
||||
}
|
||||
|
||||
func (ctl *Controller) UnlockEvents() {
|
||||
persistentClients.eventsPaused.Done()
|
||||
}
|
||||
@ -22,6 +22,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/ProtonMail/go-srp"
|
||||
"github.com/ProtonMail/proton-bridge/internal/constants"
|
||||
@ -47,6 +48,8 @@ var persistentClients = struct {
|
||||
manager pmapi.Manager
|
||||
byName map[string]clientAuthGetter
|
||||
saltByName map[string]string
|
||||
|
||||
eventsPaused sync.WaitGroup
|
||||
}{}
|
||||
|
||||
type persistentClient struct {
|
||||
@ -69,6 +72,17 @@ func (pc *persistentClient) AuthSalt(_ context.Context) (string, error) {
|
||||
return persistentClients.saltByName[pc.username], nil
|
||||
}
|
||||
|
||||
// GetEvent needs to wait for preparation to finish. Otherwise messages will be
|
||||
// in wrong order and test will fail.
|
||||
func (pc *persistentClient) GetEvent(ctx context.Context, eventID string) (*pmapi.Event, error) {
|
||||
persistentClients.eventsPaused.Wait()
|
||||
normalClient, ok := persistentClients.byName[pc.username].(pmapi.Client)
|
||||
if !ok {
|
||||
return nil, errors.New("cannot convert to normal client")
|
||||
}
|
||||
return normalClient.GetEvent(ctx, eventID)
|
||||
}
|
||||
|
||||
func SetupPersistentClients() {
|
||||
app := os.Getenv("TEST_APP")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user