mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 06:59:57 +00:00
TUN-7227: Migrate to devincarr/quic-go
The lucas-clemente/quic-go package moved namespaces and our branch went stale, this new fork provides support for the new quic-go repo and applies the max datagram frame size change. Until the max datagram frame size support gets upstreamed into quic-go, this can be used to unblock go 1.20 support as the old lucas-clemente/quic-go will not get go 1.20 support.
This commit is contained in:
162
vendor/github.com/onsi/ginkgo/v2/internal/interrupt_handler/interrupt_handler.go
generated
vendored
Normal file
162
vendor/github.com/onsi/ginkgo/v2/internal/interrupt_handler/interrupt_handler.go
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
package interrupt_handler
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2/internal/parallel_support"
|
||||
)
|
||||
|
||||
const ABORT_POLLING_INTERVAL = 500 * time.Millisecond
|
||||
|
||||
type InterruptCause uint
|
||||
|
||||
const (
|
||||
InterruptCauseInvalid InterruptCause = iota
|
||||
InterruptCauseSignal
|
||||
InterruptCauseAbortByOtherProcess
|
||||
)
|
||||
|
||||
type InterruptLevel uint
|
||||
|
||||
const (
|
||||
InterruptLevelUninterrupted InterruptLevel = iota
|
||||
InterruptLevelCleanupAndReport
|
||||
InterruptLevelReportOnly
|
||||
InterruptLevelBailOut
|
||||
)
|
||||
|
||||
func (ic InterruptCause) String() string {
|
||||
switch ic {
|
||||
case InterruptCauseSignal:
|
||||
return "Interrupted by User"
|
||||
case InterruptCauseAbortByOtherProcess:
|
||||
return "Interrupted by Other Ginkgo Process"
|
||||
}
|
||||
return "INVALID_INTERRUPT_CAUSE"
|
||||
}
|
||||
|
||||
type InterruptStatus struct {
|
||||
Channel chan interface{}
|
||||
Level InterruptLevel
|
||||
Cause InterruptCause
|
||||
}
|
||||
|
||||
func (s InterruptStatus) Interrupted() bool {
|
||||
return s.Level != InterruptLevelUninterrupted
|
||||
}
|
||||
|
||||
func (s InterruptStatus) Message() string {
|
||||
return s.Cause.String()
|
||||
}
|
||||
|
||||
func (s InterruptStatus) ShouldIncludeProgressReport() bool {
|
||||
return s.Cause != InterruptCauseAbortByOtherProcess
|
||||
}
|
||||
|
||||
type InterruptHandlerInterface interface {
|
||||
Status() InterruptStatus
|
||||
}
|
||||
|
||||
type InterruptHandler struct {
|
||||
c chan interface{}
|
||||
lock *sync.Mutex
|
||||
level InterruptLevel
|
||||
cause InterruptCause
|
||||
client parallel_support.Client
|
||||
stop chan interface{}
|
||||
signals []os.Signal
|
||||
}
|
||||
|
||||
func NewInterruptHandler(client parallel_support.Client, signals ...os.Signal) *InterruptHandler {
|
||||
if len(signals) == 0 {
|
||||
signals = []os.Signal{os.Interrupt, syscall.SIGTERM}
|
||||
}
|
||||
handler := &InterruptHandler{
|
||||
c: make(chan interface{}),
|
||||
lock: &sync.Mutex{},
|
||||
stop: make(chan interface{}),
|
||||
client: client,
|
||||
signals: signals,
|
||||
}
|
||||
handler.registerForInterrupts()
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *InterruptHandler) Stop() {
|
||||
close(handler.stop)
|
||||
}
|
||||
|
||||
func (handler *InterruptHandler) registerForInterrupts() {
|
||||
// os signal handling
|
||||
signalChannel := make(chan os.Signal, 1)
|
||||
signal.Notify(signalChannel, handler.signals...)
|
||||
|
||||
// cross-process abort handling
|
||||
var abortChannel chan interface{}
|
||||
if handler.client != nil {
|
||||
abortChannel = make(chan interface{})
|
||||
go func() {
|
||||
pollTicker := time.NewTicker(ABORT_POLLING_INTERVAL)
|
||||
for {
|
||||
select {
|
||||
case <-pollTicker.C:
|
||||
if handler.client.ShouldAbort() {
|
||||
close(abortChannel)
|
||||
pollTicker.Stop()
|
||||
return
|
||||
}
|
||||
case <-handler.stop:
|
||||
pollTicker.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
go func(abortChannel chan interface{}) {
|
||||
var interruptCause InterruptCause
|
||||
for {
|
||||
select {
|
||||
case <-signalChannel:
|
||||
interruptCause = InterruptCauseSignal
|
||||
case <-abortChannel:
|
||||
interruptCause = InterruptCauseAbortByOtherProcess
|
||||
case <-handler.stop:
|
||||
signal.Stop(signalChannel)
|
||||
return
|
||||
}
|
||||
abortChannel = nil
|
||||
|
||||
handler.lock.Lock()
|
||||
oldLevel := handler.level
|
||||
handler.cause = interruptCause
|
||||
if handler.level == InterruptLevelUninterrupted {
|
||||
handler.level = InterruptLevelCleanupAndReport
|
||||
} else if handler.level == InterruptLevelCleanupAndReport {
|
||||
handler.level = InterruptLevelReportOnly
|
||||
} else if handler.level == InterruptLevelReportOnly {
|
||||
handler.level = InterruptLevelBailOut
|
||||
}
|
||||
if handler.level != oldLevel {
|
||||
close(handler.c)
|
||||
handler.c = make(chan interface{})
|
||||
}
|
||||
handler.lock.Unlock()
|
||||
}
|
||||
}(abortChannel)
|
||||
}
|
||||
|
||||
func (handler *InterruptHandler) Status() InterruptStatus {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
|
||||
return InterruptStatus{
|
||||
Level: handler.level,
|
||||
Channel: handler.c,
|
||||
Cause: handler.cause,
|
||||
}
|
||||
}
|
15
vendor/github.com/onsi/ginkgo/v2/internal/interrupt_handler/sigquit_swallower_unix.go
generated
vendored
Normal file
15
vendor/github.com/onsi/ginkgo/v2/internal/interrupt_handler/sigquit_swallower_unix.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
//go:build freebsd || openbsd || netbsd || dragonfly || darwin || linux || solaris
|
||||
// +build freebsd openbsd netbsd dragonfly darwin linux solaris
|
||||
|
||||
package interrupt_handler
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func SwallowSigQuit() {
|
||||
c := make(chan os.Signal, 1024)
|
||||
signal.Notify(c, syscall.SIGQUIT)
|
||||
}
|
8
vendor/github.com/onsi/ginkgo/v2/internal/interrupt_handler/sigquit_swallower_windows.go
generated
vendored
Normal file
8
vendor/github.com/onsi/ginkgo/v2/internal/interrupt_handler/sigquit_swallower_windows.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package interrupt_handler
|
||||
|
||||
func SwallowSigQuit() {
|
||||
//noop
|
||||
}
|
70
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/client_server.go
generated
vendored
Normal file
70
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/client_server.go
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
package parallel_support
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2/reporters"
|
||||
"github.com/onsi/ginkgo/v2/types"
|
||||
)
|
||||
|
||||
type BeforeSuiteState struct {
|
||||
Data []byte
|
||||
State types.SpecState
|
||||
}
|
||||
|
||||
type ParallelIndexCounter struct {
|
||||
Index int
|
||||
}
|
||||
|
||||
var ErrorGone = fmt.Errorf("gone")
|
||||
var ErrorFailed = fmt.Errorf("failed")
|
||||
var ErrorEarly = fmt.Errorf("early")
|
||||
|
||||
var POLLING_INTERVAL = 50 * time.Millisecond
|
||||
|
||||
type Server interface {
|
||||
Start()
|
||||
Close()
|
||||
Address() string
|
||||
RegisterAlive(node int, alive func() bool)
|
||||
GetSuiteDone() chan interface{}
|
||||
GetOutputDestination() io.Writer
|
||||
SetOutputDestination(io.Writer)
|
||||
}
|
||||
|
||||
type Client interface {
|
||||
Connect() bool
|
||||
Close() error
|
||||
|
||||
PostSuiteWillBegin(report types.Report) error
|
||||
PostDidRun(report types.SpecReport) error
|
||||
PostSuiteDidEnd(report types.Report) error
|
||||
PostSynchronizedBeforeSuiteCompleted(state types.SpecState, data []byte) error
|
||||
BlockUntilSynchronizedBeforeSuiteData() (types.SpecState, []byte, error)
|
||||
BlockUntilNonprimaryProcsHaveFinished() error
|
||||
BlockUntilAggregatedNonprimaryProcsReport() (types.Report, error)
|
||||
FetchNextCounter() (int, error)
|
||||
PostAbort() error
|
||||
ShouldAbort() bool
|
||||
PostEmitProgressReport(report types.ProgressReport) error
|
||||
Write(p []byte) (int, error)
|
||||
}
|
||||
|
||||
func NewServer(parallelTotal int, reporter reporters.Reporter) (Server, error) {
|
||||
if os.Getenv("GINKGO_PARALLEL_PROTOCOL") == "HTTP" {
|
||||
return newHttpServer(parallelTotal, reporter)
|
||||
} else {
|
||||
return newRPCServer(parallelTotal, reporter)
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(serverHost string) Client {
|
||||
if os.Getenv("GINKGO_PARALLEL_PROTOCOL") == "HTTP" {
|
||||
return newHttpClient(serverHost)
|
||||
} else {
|
||||
return newRPCClient(serverHost)
|
||||
}
|
||||
}
|
156
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/http_client.go
generated
vendored
Normal file
156
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/http_client.go
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
package parallel_support
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2/types"
|
||||
)
|
||||
|
||||
type httpClient struct {
|
||||
serverHost string
|
||||
}
|
||||
|
||||
func newHttpClient(serverHost string) *httpClient {
|
||||
return &httpClient{
|
||||
serverHost: serverHost,
|
||||
}
|
||||
}
|
||||
|
||||
func (client *httpClient) Connect() bool {
|
||||
resp, err := http.Get(client.serverHost + "/up")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
resp.Body.Close()
|
||||
return resp.StatusCode == http.StatusOK
|
||||
}
|
||||
|
||||
func (client *httpClient) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (client *httpClient) post(path string, data interface{}) error {
|
||||
var body io.Reader
|
||||
if data != nil {
|
||||
encoded, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
body = bytes.NewBuffer(encoded)
|
||||
}
|
||||
resp, err := http.Post(client.serverHost+path, "application/json", body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("received unexpected status code %d", resp.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (client *httpClient) poll(path string, data interface{}) error {
|
||||
for {
|
||||
resp, err := http.Get(client.serverHost + path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode == http.StatusTooEarly {
|
||||
resp.Body.Close()
|
||||
time.Sleep(POLLING_INTERVAL)
|
||||
continue
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == http.StatusGone {
|
||||
return ErrorGone
|
||||
}
|
||||
if resp.StatusCode == http.StatusFailedDependency {
|
||||
return ErrorFailed
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("received unexpected status code %d", resp.StatusCode)
|
||||
}
|
||||
if data != nil {
|
||||
return json.NewDecoder(resp.Body).Decode(data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (client *httpClient) PostSuiteWillBegin(report types.Report) error {
|
||||
return client.post("/suite-will-begin", report)
|
||||
}
|
||||
|
||||
func (client *httpClient) PostDidRun(report types.SpecReport) error {
|
||||
return client.post("/did-run", report)
|
||||
}
|
||||
|
||||
func (client *httpClient) PostSuiteDidEnd(report types.Report) error {
|
||||
return client.post("/suite-did-end", report)
|
||||
}
|
||||
|
||||
func (client *httpClient) PostEmitProgressReport(report types.ProgressReport) error {
|
||||
return client.post("/progress-report", report)
|
||||
}
|
||||
|
||||
func (client *httpClient) PostSynchronizedBeforeSuiteCompleted(state types.SpecState, data []byte) error {
|
||||
beforeSuiteState := BeforeSuiteState{
|
||||
State: state,
|
||||
Data: data,
|
||||
}
|
||||
return client.post("/before-suite-completed", beforeSuiteState)
|
||||
}
|
||||
|
||||
func (client *httpClient) BlockUntilSynchronizedBeforeSuiteData() (types.SpecState, []byte, error) {
|
||||
var beforeSuiteState BeforeSuiteState
|
||||
err := client.poll("/before-suite-state", &beforeSuiteState)
|
||||
if err == ErrorGone {
|
||||
return types.SpecStateInvalid, nil, types.GinkgoErrors.SynchronizedBeforeSuiteDisappearedOnProc1()
|
||||
}
|
||||
return beforeSuiteState.State, beforeSuiteState.Data, err
|
||||
}
|
||||
|
||||
func (client *httpClient) BlockUntilNonprimaryProcsHaveFinished() error {
|
||||
return client.poll("/have-nonprimary-procs-finished", nil)
|
||||
}
|
||||
|
||||
func (client *httpClient) BlockUntilAggregatedNonprimaryProcsReport() (types.Report, error) {
|
||||
var report types.Report
|
||||
err := client.poll("/aggregated-nonprimary-procs-report", &report)
|
||||
if err == ErrorGone {
|
||||
return types.Report{}, types.GinkgoErrors.AggregatedReportUnavailableDueToNodeDisappearing()
|
||||
}
|
||||
return report, err
|
||||
}
|
||||
|
||||
func (client *httpClient) FetchNextCounter() (int, error) {
|
||||
var counter ParallelIndexCounter
|
||||
err := client.poll("/counter", &counter)
|
||||
return counter.Index, err
|
||||
}
|
||||
|
||||
func (client *httpClient) PostAbort() error {
|
||||
return client.post("/abort", nil)
|
||||
}
|
||||
|
||||
func (client *httpClient) ShouldAbort() bool {
|
||||
err := client.poll("/abort", nil)
|
||||
if err == ErrorGone {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (client *httpClient) Write(p []byte) (int, error) {
|
||||
resp, err := http.Post(client.serverHost+"/emit-output", "text/plain;charset=UTF-8 ", bytes.NewReader(p))
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return 0, fmt.Errorf("failed to emit output")
|
||||
}
|
||||
return len(p), err
|
||||
}
|
223
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/http_server.go
generated
vendored
Normal file
223
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/http_server.go
generated
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
|
||||
The remote package provides the pieces to allow Ginkgo test suites to report to remote listeners.
|
||||
This is used, primarily, to enable streaming parallel test output but has, in principal, broader applications (e.g. streaming test output to a browser).
|
||||
|
||||
*/
|
||||
|
||||
package parallel_support
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/onsi/ginkgo/v2/reporters"
|
||||
"github.com/onsi/ginkgo/v2/types"
|
||||
)
|
||||
|
||||
/*
|
||||
httpServer spins up on an automatically selected port and listens for communication from the forwarding reporter.
|
||||
It then forwards that communication to attached reporters.
|
||||
*/
|
||||
type httpServer struct {
|
||||
listener net.Listener
|
||||
handler *ServerHandler
|
||||
}
|
||||
|
||||
//Create a new server, automatically selecting a port
|
||||
func newHttpServer(parallelTotal int, reporter reporters.Reporter) (*httpServer, error) {
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &httpServer{
|
||||
listener: listener,
|
||||
handler: newServerHandler(parallelTotal, reporter),
|
||||
}, nil
|
||||
}
|
||||
|
||||
//Start the server. You don't need to `go s.Start()`, just `s.Start()`
|
||||
func (server *httpServer) Start() {
|
||||
httpServer := &http.Server{}
|
||||
mux := http.NewServeMux()
|
||||
httpServer.Handler = mux
|
||||
|
||||
//streaming endpoints
|
||||
mux.HandleFunc("/suite-will-begin", server.specSuiteWillBegin)
|
||||
mux.HandleFunc("/did-run", server.didRun)
|
||||
mux.HandleFunc("/suite-did-end", server.specSuiteDidEnd)
|
||||
mux.HandleFunc("/emit-output", server.emitOutput)
|
||||
mux.HandleFunc("/progress-report", server.emitProgressReport)
|
||||
|
||||
//synchronization endpoints
|
||||
mux.HandleFunc("/before-suite-completed", server.handleBeforeSuiteCompleted)
|
||||
mux.HandleFunc("/before-suite-state", server.handleBeforeSuiteState)
|
||||
mux.HandleFunc("/have-nonprimary-procs-finished", server.handleHaveNonprimaryProcsFinished)
|
||||
mux.HandleFunc("/aggregated-nonprimary-procs-report", server.handleAggregatedNonprimaryProcsReport)
|
||||
mux.HandleFunc("/counter", server.handleCounter)
|
||||
mux.HandleFunc("/up", server.handleUp)
|
||||
mux.HandleFunc("/abort", server.handleAbort)
|
||||
|
||||
go httpServer.Serve(server.listener)
|
||||
}
|
||||
|
||||
//Stop the server
|
||||
func (server *httpServer) Close() {
|
||||
server.listener.Close()
|
||||
}
|
||||
|
||||
//The address the server can be reached it. Pass this into the `ForwardingReporter`.
|
||||
func (server *httpServer) Address() string {
|
||||
return "http://" + server.listener.Addr().String()
|
||||
}
|
||||
|
||||
func (server *httpServer) GetSuiteDone() chan interface{} {
|
||||
return server.handler.done
|
||||
}
|
||||
|
||||
func (server *httpServer) GetOutputDestination() io.Writer {
|
||||
return server.handler.outputDestination
|
||||
}
|
||||
|
||||
func (server *httpServer) SetOutputDestination(w io.Writer) {
|
||||
server.handler.outputDestination = w
|
||||
}
|
||||
|
||||
func (server *httpServer) RegisterAlive(node int, alive func() bool) {
|
||||
server.handler.registerAlive(node, alive)
|
||||
}
|
||||
|
||||
//
|
||||
// Streaming Endpoints
|
||||
//
|
||||
|
||||
//The server will forward all received messages to Ginkgo reporters registered with `RegisterReporters`
|
||||
func (server *httpServer) decode(writer http.ResponseWriter, request *http.Request, object interface{}) bool {
|
||||
defer request.Body.Close()
|
||||
if json.NewDecoder(request.Body).Decode(object) != nil {
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (server *httpServer) handleError(err error, writer http.ResponseWriter) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
switch err {
|
||||
case ErrorEarly:
|
||||
writer.WriteHeader(http.StatusTooEarly)
|
||||
case ErrorGone:
|
||||
writer.WriteHeader(http.StatusGone)
|
||||
case ErrorFailed:
|
||||
writer.WriteHeader(http.StatusFailedDependency)
|
||||
default:
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (server *httpServer) specSuiteWillBegin(writer http.ResponseWriter, request *http.Request) {
|
||||
var report types.Report
|
||||
if !server.decode(writer, request, &report) {
|
||||
return
|
||||
}
|
||||
|
||||
server.handleError(server.handler.SpecSuiteWillBegin(report, voidReceiver), writer)
|
||||
}
|
||||
|
||||
func (server *httpServer) didRun(writer http.ResponseWriter, request *http.Request) {
|
||||
var report types.SpecReport
|
||||
if !server.decode(writer, request, &report) {
|
||||
return
|
||||
}
|
||||
|
||||
server.handleError(server.handler.DidRun(report, voidReceiver), writer)
|
||||
}
|
||||
|
||||
func (server *httpServer) specSuiteDidEnd(writer http.ResponseWriter, request *http.Request) {
|
||||
var report types.Report
|
||||
if !server.decode(writer, request, &report) {
|
||||
return
|
||||
}
|
||||
server.handleError(server.handler.SpecSuiteDidEnd(report, voidReceiver), writer)
|
||||
}
|
||||
|
||||
func (server *httpServer) emitOutput(writer http.ResponseWriter, request *http.Request) {
|
||||
output, err := io.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
var n int
|
||||
server.handleError(server.handler.EmitOutput(output, &n), writer)
|
||||
}
|
||||
|
||||
func (server *httpServer) emitProgressReport(writer http.ResponseWriter, request *http.Request) {
|
||||
var report types.ProgressReport
|
||||
if !server.decode(writer, request, &report) {
|
||||
return
|
||||
}
|
||||
server.handleError(server.handler.EmitProgressReport(report, voidReceiver), writer)
|
||||
}
|
||||
|
||||
func (server *httpServer) handleBeforeSuiteCompleted(writer http.ResponseWriter, request *http.Request) {
|
||||
var beforeSuiteState BeforeSuiteState
|
||||
if !server.decode(writer, request, &beforeSuiteState) {
|
||||
return
|
||||
}
|
||||
|
||||
server.handleError(server.handler.BeforeSuiteCompleted(beforeSuiteState, voidReceiver), writer)
|
||||
}
|
||||
|
||||
func (server *httpServer) handleBeforeSuiteState(writer http.ResponseWriter, request *http.Request) {
|
||||
var beforeSuiteState BeforeSuiteState
|
||||
if server.handleError(server.handler.BeforeSuiteState(voidSender, &beforeSuiteState), writer) {
|
||||
return
|
||||
}
|
||||
json.NewEncoder(writer).Encode(beforeSuiteState)
|
||||
}
|
||||
|
||||
func (server *httpServer) handleHaveNonprimaryProcsFinished(writer http.ResponseWriter, request *http.Request) {
|
||||
if server.handleError(server.handler.HaveNonprimaryProcsFinished(voidSender, voidReceiver), writer) {
|
||||
return
|
||||
}
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (server *httpServer) handleAggregatedNonprimaryProcsReport(writer http.ResponseWriter, request *http.Request) {
|
||||
var aggregatedReport types.Report
|
||||
if server.handleError(server.handler.AggregatedNonprimaryProcsReport(voidSender, &aggregatedReport), writer) {
|
||||
return
|
||||
}
|
||||
json.NewEncoder(writer).Encode(aggregatedReport)
|
||||
}
|
||||
|
||||
func (server *httpServer) handleCounter(writer http.ResponseWriter, request *http.Request) {
|
||||
var n int
|
||||
if server.handleError(server.handler.Counter(voidSender, &n), writer) {
|
||||
return
|
||||
}
|
||||
json.NewEncoder(writer).Encode(ParallelIndexCounter{Index: n})
|
||||
}
|
||||
|
||||
func (server *httpServer) handleUp(writer http.ResponseWriter, request *http.Request) {
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (server *httpServer) handleAbort(writer http.ResponseWriter, request *http.Request) {
|
||||
if request.Method == "GET" {
|
||||
var shouldAbort bool
|
||||
server.handler.ShouldAbort(voidSender, &shouldAbort)
|
||||
if shouldAbort {
|
||||
writer.WriteHeader(http.StatusGone)
|
||||
} else {
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
}
|
||||
} else {
|
||||
server.handler.Abort(voidSender, voidReceiver)
|
||||
}
|
||||
}
|
123
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/rpc_client.go
generated
vendored
Normal file
123
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/rpc_client.go
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
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) 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
|
||||
}
|
75
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/rpc_server.go
generated
vendored
Normal file
75
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/rpc_server.go
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
|
||||
The remote package provides the pieces to allow Ginkgo test suites to report to remote listeners.
|
||||
This is used, primarily, to enable streaming parallel test output but has, in principal, broader applications (e.g. streaming test output to a browser).
|
||||
|
||||
*/
|
||||
|
||||
package parallel_support
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/rpc"
|
||||
|
||||
"github.com/onsi/ginkgo/v2/reporters"
|
||||
)
|
||||
|
||||
/*
|
||||
RPCServer spins up on an automatically selected port and listens for communication from the forwarding reporter.
|
||||
It then forwards that communication to attached reporters.
|
||||
*/
|
||||
type RPCServer struct {
|
||||
listener net.Listener
|
||||
handler *ServerHandler
|
||||
}
|
||||
|
||||
//Create a new server, automatically selecting a port
|
||||
func newRPCServer(parallelTotal int, reporter reporters.Reporter) (*RPCServer, error) {
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &RPCServer{
|
||||
listener: listener,
|
||||
handler: newServerHandler(parallelTotal, reporter),
|
||||
}, nil
|
||||
}
|
||||
|
||||
//Start the server. You don't need to `go s.Start()`, just `s.Start()`
|
||||
func (server *RPCServer) Start() {
|
||||
rpcServer := rpc.NewServer()
|
||||
rpcServer.RegisterName("Server", server.handler) //register the handler's methods as the server
|
||||
|
||||
httpServer := &http.Server{}
|
||||
httpServer.Handler = rpcServer
|
||||
|
||||
go httpServer.Serve(server.listener)
|
||||
}
|
||||
|
||||
//Stop the server
|
||||
func (server *RPCServer) Close() {
|
||||
server.listener.Close()
|
||||
}
|
||||
|
||||
//The address the server can be reached it. Pass this into the `ForwardingReporter`.
|
||||
func (server *RPCServer) Address() string {
|
||||
return server.listener.Addr().String()
|
||||
}
|
||||
|
||||
func (server *RPCServer) GetSuiteDone() chan interface{} {
|
||||
return server.handler.done
|
||||
}
|
||||
|
||||
func (server *RPCServer) GetOutputDestination() io.Writer {
|
||||
return server.handler.outputDestination
|
||||
}
|
||||
|
||||
func (server *RPCServer) SetOutputDestination(w io.Writer) {
|
||||
server.handler.outputDestination = w
|
||||
}
|
||||
|
||||
func (server *RPCServer) RegisterAlive(node int, alive func() bool) {
|
||||
server.handler.registerAlive(node, alive)
|
||||
}
|
209
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/server_handler.go
generated
vendored
Normal file
209
vendor/github.com/onsi/ginkgo/v2/internal/parallel_support/server_handler.go
generated
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
package parallel_support
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/onsi/ginkgo/v2/reporters"
|
||||
"github.com/onsi/ginkgo/v2/types"
|
||||
)
|
||||
|
||||
type Void struct{}
|
||||
|
||||
var voidReceiver *Void = &Void{}
|
||||
var voidSender Void
|
||||
|
||||
// ServerHandler is an RPC-compatible handler that is shared between the http server and the rpc server.
|
||||
// It handles all the business logic to avoid duplication between the two servers
|
||||
|
||||
type ServerHandler struct {
|
||||
done chan interface{}
|
||||
outputDestination io.Writer
|
||||
reporter reporters.Reporter
|
||||
alives []func() bool
|
||||
lock *sync.Mutex
|
||||
beforeSuiteState BeforeSuiteState
|
||||
parallelTotal int
|
||||
counter int
|
||||
counterLock *sync.Mutex
|
||||
shouldAbort bool
|
||||
|
||||
numSuiteDidBegins int
|
||||
numSuiteDidEnds int
|
||||
aggregatedReport types.Report
|
||||
reportHoldingArea []types.SpecReport
|
||||
}
|
||||
|
||||
func newServerHandler(parallelTotal int, reporter reporters.Reporter) *ServerHandler {
|
||||
return &ServerHandler{
|
||||
reporter: reporter,
|
||||
lock: &sync.Mutex{},
|
||||
counterLock: &sync.Mutex{},
|
||||
alives: make([]func() bool, parallelTotal),
|
||||
beforeSuiteState: BeforeSuiteState{Data: nil, State: types.SpecStateInvalid},
|
||||
parallelTotal: parallelTotal,
|
||||
outputDestination: os.Stdout,
|
||||
done: make(chan interface{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) SpecSuiteWillBegin(report types.Report, _ *Void) error {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
|
||||
handler.numSuiteDidBegins += 1
|
||||
|
||||
// all summaries are identical, so it's fine to simply emit the last one of these
|
||||
if handler.numSuiteDidBegins == handler.parallelTotal {
|
||||
handler.reporter.SuiteWillBegin(report)
|
||||
|
||||
for _, summary := range handler.reportHoldingArea {
|
||||
handler.reporter.WillRun(summary)
|
||||
handler.reporter.DidRun(summary)
|
||||
}
|
||||
|
||||
handler.reportHoldingArea = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) DidRun(report types.SpecReport, _ *Void) error {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
|
||||
if handler.numSuiteDidBegins == handler.parallelTotal {
|
||||
handler.reporter.WillRun(report)
|
||||
handler.reporter.DidRun(report)
|
||||
} else {
|
||||
handler.reportHoldingArea = append(handler.reportHoldingArea, report)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) SpecSuiteDidEnd(report types.Report, _ *Void) error {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
|
||||
handler.numSuiteDidEnds += 1
|
||||
if handler.numSuiteDidEnds == 1 {
|
||||
handler.aggregatedReport = report
|
||||
} else {
|
||||
handler.aggregatedReport = handler.aggregatedReport.Add(report)
|
||||
}
|
||||
|
||||
if handler.numSuiteDidEnds == handler.parallelTotal {
|
||||
handler.reporter.SuiteDidEnd(handler.aggregatedReport)
|
||||
close(handler.done)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) EmitOutput(output []byte, n *int) error {
|
||||
var err error
|
||||
*n, err = handler.outputDestination.Write(output)
|
||||
return err
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) EmitProgressReport(report types.ProgressReport, _ *Void) error {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
handler.reporter.EmitProgressReport(report)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) registerAlive(proc int, alive func() bool) {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
handler.alives[proc-1] = alive
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) procIsAlive(proc int) bool {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
alive := handler.alives[proc-1]
|
||||
if alive == nil {
|
||||
return true
|
||||
}
|
||||
return alive()
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) haveNonprimaryProcsFinished() bool {
|
||||
for i := 2; i <= handler.parallelTotal; i++ {
|
||||
if handler.procIsAlive(i) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) BeforeSuiteCompleted(beforeSuiteState BeforeSuiteState, _ *Void) error {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
handler.beforeSuiteState = beforeSuiteState
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) BeforeSuiteState(_ Void, beforeSuiteState *BeforeSuiteState) error {
|
||||
proc1IsAlive := handler.procIsAlive(1)
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
if handler.beforeSuiteState.State == types.SpecStateInvalid {
|
||||
if proc1IsAlive {
|
||||
return ErrorEarly
|
||||
} else {
|
||||
return ErrorGone
|
||||
}
|
||||
}
|
||||
*beforeSuiteState = handler.beforeSuiteState
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) HaveNonprimaryProcsFinished(_ Void, _ *Void) error {
|
||||
if handler.haveNonprimaryProcsFinished() {
|
||||
return nil
|
||||
} else {
|
||||
return ErrorEarly
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) AggregatedNonprimaryProcsReport(_ Void, report *types.Report) error {
|
||||
if handler.haveNonprimaryProcsFinished() {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
if handler.numSuiteDidEnds == handler.parallelTotal-1 {
|
||||
*report = handler.aggregatedReport
|
||||
return nil
|
||||
} else {
|
||||
return ErrorGone
|
||||
}
|
||||
} else {
|
||||
return ErrorEarly
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) Counter(_ Void, counter *int) error {
|
||||
handler.counterLock.Lock()
|
||||
defer handler.counterLock.Unlock()
|
||||
*counter = handler.counter
|
||||
handler.counter++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) Abort(_ Void, _ *Void) error {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
handler.shouldAbort = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *ServerHandler) ShouldAbort(_ Void, shouldAbort *bool) error {
|
||||
handler.lock.Lock()
|
||||
defer handler.lock.Unlock()
|
||||
*shouldAbort = handler.shouldAbort
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user