Files
ziti/tests/testutil/timeout_underlay.go
Paul Lorenz 1c122af490 Rewrite channel/v4 imports to channel/v5. For #3983
- moves the channel dependency to channel/v5 v5.0.10 and sdk-golang to v1.9.0 in the root and zititest modules
- mechanically rewrites every channel/v4 import path to channel/v5

This is the import-path-only step; the API-level changes the switch requires land in the following commit. This commit does not build on its own.
2026-06-18 12:51:02 -04:00

43 lines
860 B
Go

package testutil
import (
"time"
"github.com/openziti/channel/v5"
"github.com/pkg/errors"
)
func NewTimeoutUnderlayFactory(factory channel.UnderlayFactory, timeout time.Duration) *UnderlayFactoryWrapper {
return &UnderlayFactoryWrapper{
timeout: timeout,
wrapped: factory,
}
}
type UnderlayFactoryWrapper struct {
timeout time.Duration
wrapped channel.UnderlayFactory
}
func (self *UnderlayFactoryWrapper) Create(timeout time.Duration) (channel.Underlay, error) {
underlayC := make(chan channel.Underlay, 1)
errC := make(chan error, 1)
go func() {
u, err := self.wrapped.Create(timeout)
if err != nil {
errC <- err
} else {
underlayC <- u
}
}()
select {
case underlay := <-underlayC:
return underlay, nil
case err := <-errC:
return nil, err
case <-time.After(self.timeout):
return nil, errors.New("timed out")
}
}