This repository was archived by the owner on Apr 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathproxy_test.go
More file actions
88 lines (71 loc) · 1.9 KB
/
proxy_test.go
File metadata and controls
88 lines (71 loc) · 1.9 KB
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
package grpc_test
import (
"context"
"net"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/test/bufconn"
grpcproxy "github.com/rollkit/go-execution/proxy/grpc"
"github.com/rollkit/go-execution/test"
pb "github.com/rollkit/go-execution/types/pb/execution"
)
const bufSize = 1024 * 1024
func dialer(listener *bufconn.Listener) func(context.Context, string) (net.Conn, error) {
return func(context.Context, string) (net.Conn, error) {
return listener.Dial()
}
}
type ProxyTestSuite struct {
test.ExecuteSuite
server *grpc.Server
client *grpcproxy.Client
cleanup func()
}
func (s *ProxyTestSuite) SetupTest() {
exec := test.NewExecute()
config := &grpcproxy.Config{
DefaultTimeout: time.Second,
MaxRequestSize: bufSize,
}
server := grpcproxy.NewServer(exec, config)
listener := bufconn.Listen(bufSize)
s.server = grpc.NewServer()
pb.RegisterExecutionServiceServer(s.server, server)
go func() {
if err := s.server.Serve(listener); err != nil && err != grpc.ErrServerStopped {
s.T().Errorf("Server exited with error: %v", err)
}
}()
client := grpcproxy.NewClient()
client.SetConfig(config)
_, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
opts := []grpc.DialOption{
grpc.WithContextDialer(dialer(listener)),
grpc.WithTransportCredentials(insecure.NewCredentials()),
}
err := client.Start("passthrough://bufnet", opts...)
require.NoError(s.T(), err)
for i := 0; i < 10; i++ {
if _, err := client.GetTxs(); err == nil {
break
}
time.Sleep(100 * time.Millisecond)
}
s.client = client
s.Exec = client
s.cleanup = func() {
_ = client.Stop()
s.server.Stop()
}
}
func (s *ProxyTestSuite) TearDownTest() {
s.cleanup()
}
func TestProxySuite(t *testing.T) {
suite.Run(t, new(ProxyTestSuite))
}