blob: 7f9bc6373d7dec92e6b2d4616bc1cb279f74722e [file] [log] [blame]
Lorenz Brunfc5dbc62020-05-28 12:18:07 +02001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17package e2e
18
19import (
20 "context"
21 "errors"
22 "time"
23
Serge Bazanskiefdb6e92020-07-13 17:19:27 +020024 apb "git.monogon.dev/source/nexantic.git/core/proto/api"
Lorenz Brunfc5dbc62020-05-28 12:18:07 +020025)
26
Serge Bazanskiefdb6e92020-07-13 17:19:27 +020027func waitForCondition(ctx context.Context, client apb.NodeDebugServiceClient, condition string) error {
Lorenz Brunfc5dbc62020-05-28 12:18:07 +020028 var lastErr = errors.New("No RPC for checking condition completed")
29 for {
Serge Bazanskiefdb6e92020-07-13 17:19:27 +020030 reqT, cancel := context.WithTimeout(ctx, 5*time.Second)
Lorenz Brun56ae5772020-07-08 18:04:48 +020031 defer cancel()
Serge Bazanskiefdb6e92020-07-13 17:19:27 +020032 res, err := client.GetCondition(reqT, &apb.GetConditionRequest{Name: condition})
Lorenz Brunfc5dbc62020-05-28 12:18:07 +020033 if err != nil {
34 if err == ctx.Err() {
35 return err
36 }
37 lastErr = err
38 }
39 if err == nil && res.Ok {
40 return nil
41 }
42 select {
43 case <-time.After(1 * time.Second):
44 case <-ctx.Done():
45 return lastErr
46 }
47 }
48}