Welcome to mirror list, hosted at ThFree Co, Russian Federation.

stream.go « testhelper « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7129f7d426939712eff55f27820941947e0ff716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package testhelper

import (
	"fmt"
	"io"
	"time"
)

// ReceiveEOFWithTimeout reads to the end of the stream and will throw an
// error if a deadlock is suspected
func ReceiveEOFWithTimeout(errorFunc func() error) error {
	errCh := make(chan error, 1)
	go func() {
		errCh <- errorFunc()
	}()

	var err error
	select {
	case err = <-errCh:
	case <-time.After(1 * time.Second):
		err = fmt.Errorf("timed out waiting for EOF")
	}

	if err == io.EOF {
		err = nil
	}

	return err
}