Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 30f389e

Browse files
committed
internal fix of proxytest / enhance docs
Signed-off-by: mathetake <[email protected]>
1 parent 0766531 commit 30f389e

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
ISTIO_VERSION ?= 1.7.2
44

5-
.PHONY: help build.example build.examples lint test test.sdk test.e2e
6-
help:
7-
grep -E '^[a-z0-9A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
5+
.PHONY: build.example build.examples lint test test.sdk test.e2e
86

97
build.example:
10-
tinygo build -o ./examples/${name}/main.go.wasm -target=wasi -wasm-abi=generic ./examples/${name}/main.go
8+
tinygo build -o ./examples/${name}/main.go.wasm -scheduler=none -target=wasi -wasm-abi=generic ./examples/${name}/main.go
119

1210
build.examples:
1311
find ./examples -type f -name "main.go" | xargs -Ip tinygo build -o p.wasm -target=wasi -wasm-abi=generic p

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ make test # run local tests without running envoy processes
8484
make test.e2e # run e2e tests
8585
```
8686

87-
## compiler limitations and considerations
87+
## limitations and considerations
8888

8989
- Some of existing libraries are not available (importable but runtime panic / non-importable)
90-
- There are two reasons for this:
90+
- There are several reasons for this:
9191
1. TinyGo's WASI target does not support some of syscall: For example, we cannot import `crypto/rand` package.
9292
2. TinyGo does not implement all of reflect package([examples](https://github.com/tinygo-org/tinygo/blob/v0.14.1/src/reflect/value.go#L299-L305)).
93-
- These issues will be mitigated as the TinyGo improves.
93+
3. [proxy-wasm-cpp-host](https://github.com/proxy-wasm/proxy-wasm-cpp-host) has not supported some of WASI APIs yet
94+
(see the [supported functions](https://github.com/proxy-wasm/proxy-wasm-cpp-host/blob/master/include/proxy-wasm/exports.h#L134-L147)).
95+
For example, `clock_time_get` is not implemented, and therefore we cannot use `time.Now`.
96+
- These issues will be mitigated as TinyGo and proxy-wasm-cpp-host evolve.
9497
- There's performance overhead in using Go/TinyGo due to GC
9598
- runtime.GC() is called whenever the heap runs out (see [1](https://tinygo.org/lang-support/#garbage-collection),
9699
[2](https://github.com/tinygo-org/tinygo/blob/v0.14.1/src/runtime/gc_conservative.go#L218-L239)).

proxytest/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ This framework simulates the expected behavior of Envoyproxy, and you can test y
1010
For detail, see `examples/*/main_test.go`.
1111

1212

13-
Note that we have not covered ll the functionality, and the API is very likely to change in the future.
13+
Note that we have not covered all the functionality, and the API is very likely to change in the future.

proxytest/proxytest.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ var (
5555
nextContextID = rootContextID + 1
5656
)
5757

58+
type hostEmulator struct {
59+
*rootHostEmulator
60+
*networkHostEmulator
61+
*httpHostEmulator
62+
63+
effectiveContextID uint32
64+
}
65+
5866
func NewHostEmulator(opt *EmulatorOption) HostEmulator {
5967
root := newRootHostEmulator(opt.pluginConfiguration, opt.vmConfiguration)
6068
network := newNetworkHostEmulator()
@@ -86,18 +94,10 @@ func getNextContextID() (ret uint32) {
8694
return
8795
}
8896

89-
type hostEmulator struct {
90-
*rootHostEmulator
91-
*networkHostEmulator
92-
*httpHostEmulator
93-
94-
effectiveContextID uint32
95-
}
96-
9797
// impl host HostEmulator
9898
func (*hostEmulator) Done() {
99-
hostMux.Unlock()
100-
proxywasm.VMStateReset()
99+
defer hostMux.Unlock()
100+
defer proxywasm.VMStateReset()
101101
}
102102

103103
// impl host rawhostcall.ProxyWASMHost

proxytest/root.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type (
4545

4646
pluginConfiguration, vmConfiguration []byte
4747

48-
activeCalloutID *uint32
48+
activeCalloutID uint32
4949
}
5050

5151
HttpCalloutAttribute struct {
@@ -258,10 +258,9 @@ func (r *rootHostEmulator) ProxyHttpCall(upstreamData *byte, upstreamSize int, h
258258

259259
// delegated from hostEmulator
260260
func (r *rootHostEmulator) rootHostEmulatorProxyGetHeaderMapPairs(mapType types.MapType, returnValueData **byte, returnValueSize *int) types.Status {
261-
activeID := proxywasm.VMStateGetActiveContextID()
262-
res, ok := r.httpCalloutResponse[*r.activeCalloutID]
261+
res, ok := r.httpCalloutResponse[r.activeCalloutID]
263262
if !ok {
264-
log.Fatalf("callout response unregistered for %d", activeID)
263+
log.Fatalf("callout response unregistered for %d", r.activeCalloutID)
265264
}
266265

267266
var raw []byte
@@ -282,10 +281,9 @@ func (r *rootHostEmulator) rootHostEmulatorProxyGetHeaderMapPairs(mapType types.
282281
// delegated from hostEmulator
283282
func (r *rootHostEmulator) rootHostEmulatorProxyGetMapValue(mapType types.MapType, keyData *byte,
284283
keySize int, returnValueData **byte, returnValueSize *int) types.Status {
285-
activeID := proxywasm.VMStateGetActiveContextID()
286-
res, ok := r.httpCalloutResponse[*r.activeCalloutID]
284+
res, ok := r.httpCalloutResponse[r.activeCalloutID]
287285
if !ok {
288-
log.Fatalf("callout response unregistered for %d", activeID)
286+
log.Fatalf("callout response unregistered for %d", r.activeCalloutID)
289287
}
290288

291289
key := proxywasm.RawBytePtrToString(keyData, keySize)
@@ -323,7 +321,7 @@ func (r *rootHostEmulator) rootHostEmulatorProxyGetBufferBytes(bt types.BufferTy
323321
buf = r.vmConfiguration
324322
case types.BufferTypeHttpCallResponseBody:
325323
activeID := proxywasm.VMStateGetActiveContextID()
326-
res, ok := r.httpCalloutResponse[*r.activeCalloutID]
324+
res, ok := r.httpCalloutResponse[r.activeCalloutID]
327325
if !ok {
328326
log.Fatalf("callout response unregistered for %d", activeID)
329327
}
@@ -381,11 +379,13 @@ func (r *rootHostEmulator) PutCalloutResponse(calloutID uint32, headers, trailer
381379
}{headers: headers, trailers: trailers, body: body}
382380

383381
// rootContextID, calloutID uint32, numHeaders, bodySize, numTrailers in
384-
r.activeCalloutID = &calloutID
382+
r.activeCalloutID = calloutID
383+
defer func() {
384+
r.activeCalloutID = 0
385+
delete(r.httpCalloutResponse, calloutID)
386+
delete(r.httpCalloutIDToContextID, calloutID)
387+
}()
385388
proxywasm.ProxyOnHttpCallResponse(rootContextID, calloutID, len(headers), len(body), len(trailers))
386-
r.activeCalloutID = nil
387-
delete(r.httpCalloutResponse, calloutID)
388-
delete(r.httpCalloutIDToContextID, calloutID)
389389
}
390390

391391
func (r *rootHostEmulator) FinishVM() {

0 commit comments

Comments
 (0)