File: rpc_client.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.15.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 4,112 kB
  • sloc: javascript: 59; sh: 14; makefile: 7
file content (136 lines) | stat: -rw-r--r-- 3,737 bytes parent folder | download | duplicates (2)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package parallel_support

import (
	"net/rpc"
	"time"

	"github.com/onsi/ginkgo/v2/types"
)

type rpcClient struct {
	serverHost string
	client     *rpc.Client
}

func newRPCClient(serverHost string) *rpcClient {
	return &rpcClient{
		serverHost: serverHost,
	}
}

func (client *rpcClient) Connect() bool {
	var err error
	if client.client != nil {
		return true
	}
	client.client, err = rpc.DialHTTPPath("tcp", client.serverHost, "/")
	if err != nil {
		client.client = nil
		return false
	}
	return true
}

func (client *rpcClient) Close() error {
	return client.client.Close()
}

func (client *rpcClient) poll(method string, data interface{}) error {
	for {
		err := client.client.Call(method, voidSender, data)
		if err == nil {
			return nil
		}
		switch err.Error() {
		case ErrorEarly.Error():
			time.Sleep(POLLING_INTERVAL)
		case ErrorGone.Error():
			return ErrorGone
		case ErrorFailed.Error():
			return ErrorFailed
		default:
			return err
		}
	}
}

func (client *rpcClient) PostSuiteWillBegin(report types.Report) error {
	return client.client.Call("Server.SpecSuiteWillBegin", report, voidReceiver)
}

func (client *rpcClient) PostDidRun(report types.SpecReport) error {
	return client.client.Call("Server.DidRun", report, voidReceiver)
}

func (client *rpcClient) PostSuiteDidEnd(report types.Report) error {
	return client.client.Call("Server.SpecSuiteDidEnd", report, voidReceiver)
}

func (client *rpcClient) Write(p []byte) (int, error) {
	var n int
	err := client.client.Call("Server.EmitOutput", p, &n)
	return n, err
}

func (client *rpcClient) PostEmitProgressReport(report types.ProgressReport) error {
	return client.client.Call("Server.EmitProgressReport", report, voidReceiver)
}

func (client *rpcClient) PostReportBeforeSuiteCompleted(state types.SpecState) error {
	return client.client.Call("Server.ReportBeforeSuiteCompleted", state, voidReceiver)
}

func (client *rpcClient) BlockUntilReportBeforeSuiteCompleted() (types.SpecState, error) {
	var state types.SpecState
	err := client.poll("Server.ReportBeforeSuiteState", &state)
	if err == ErrorGone {
		return types.SpecStateFailed, nil
	}
	return state, err
}

func (client *rpcClient) PostSynchronizedBeforeSuiteCompleted(state types.SpecState, data []byte) error {
	beforeSuiteState := BeforeSuiteState{
		State: state,
		Data:  data,
	}
	return client.client.Call("Server.BeforeSuiteCompleted", beforeSuiteState, voidReceiver)
}

func (client *rpcClient) BlockUntilSynchronizedBeforeSuiteData() (types.SpecState, []byte, error) {
	var beforeSuiteState BeforeSuiteState
	err := client.poll("Server.BeforeSuiteState", &beforeSuiteState)
	if err == ErrorGone {
		return types.SpecStateInvalid, nil, types.GinkgoErrors.SynchronizedBeforeSuiteDisappearedOnProc1()
	}
	return beforeSuiteState.State, beforeSuiteState.Data, err
}

func (client *rpcClient) BlockUntilNonprimaryProcsHaveFinished() error {
	return client.poll("Server.HaveNonprimaryProcsFinished", voidReceiver)
}

func (client *rpcClient) BlockUntilAggregatedNonprimaryProcsReport() (types.Report, error) {
	var report types.Report
	err := client.poll("Server.AggregatedNonprimaryProcsReport", &report)
	if err == ErrorGone {
		return types.Report{}, types.GinkgoErrors.AggregatedReportUnavailableDueToNodeDisappearing()
	}
	return report, err
}

func (client *rpcClient) FetchNextCounter() (int, error) {
	var counter int
	err := client.client.Call("Server.Counter", voidSender, &counter)
	return counter, err
}

func (client *rpcClient) PostAbort() error {
	return client.client.Call("Server.Abort", voidSender, voidReceiver)
}

func (client *rpcClient) ShouldAbort() bool {
	var shouldAbort bool
	client.client.Call("Server.ShouldAbort", voidSender, &shouldAbort)
	return shouldAbort
}