GODT-1409 Wait in GetEvents during message preparation for live API.

This commit is contained in:
Jakub
2021-11-19 09:40:57 +01:00
parent 1d9855a190
commit 59075f2e26
6 changed files with 65 additions and 0 deletions

View File

@ -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")