Skip to content

Commit beae30b

Browse files
committed
check baggage contents in IT
Signed-off-by: Cassandra Coyle <[email protected]>
1 parent adb23de commit beae30b

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

tests/integration/suite/daprd/tracing/baggage/grpc.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package baggage
1515

1616
import (
1717
"context"
18+
"strings"
1819
"sync/atomic"
1920
"testing"
2021

@@ -40,17 +41,20 @@ type grpcBaggage struct {
4041
grpcapp *procgrpc.App
4142
daprd *daprd.Daprd
4243

43-
baggage atomic.Bool
44+
baggage atomic.Bool
45+
baggageVals atomic.Value
4446
}
4547

4648
func (g *grpcBaggage) Setup(t *testing.T) []framework.Option {
4749
g.grpcapp = procgrpc.New(t,
4850
procgrpc.WithOnInvokeFn(func(ctx context.Context, in *common.InvokeRequest) (*common.InvokeResponse, error) {
4951
if md, ok := grpcMetadata.FromIncomingContext(ctx); ok {
50-
if _, exists := md["baggage"]; exists {
52+
if baggage, exists := md["baggage"]; exists {
5153
g.baggage.Store(true)
54+
g.baggageVals.Store(strings.Join(baggage, ","))
5255
} else {
5356
g.baggage.Store(false)
57+
g.baggageVals.Store("")
5458
}
5559
}
5660
return nil, nil
@@ -86,6 +90,7 @@ func (g *grpcBaggage) Run(t *testing.T, ctx context.Context) {
8690
require.NoError(t, err)
8791
require.NotNil(t, svcresp)
8892
assert.False(t, g.baggage.Load())
93+
assert.Equal(t, "", g.baggageVals.Load())
8994
})
9095

9196
t.Run("baggage header provided", func(t *testing.T) {
@@ -102,20 +107,22 @@ func (g *grpcBaggage) Run(t *testing.T, ctx context.Context) {
102107
},
103108
}
104109

110+
baggageVal := "key1=value1,key2=value2"
105111
ctx = grpcMetadata.AppendToOutgoingContext(t.Context(),
106-
"baggage", "key1=value1,key2=value2",
112+
"baggage", baggageVal,
107113
)
108114
svcresp, err := client.InvokeService(ctx, &svcreq)
109115
require.NoError(t, err)
110116
require.NotNil(t, svcresp)
111117
assert.True(t, g.baggage.Load())
118+
assert.Equal(t, baggageVal, g.baggageVals.Load())
112119

113120
// Verify baggage header is in response metadata
114121
md, ok := grpcMetadata.FromOutgoingContext(ctx)
115122
require.True(t, ok)
116123
baggage := md.Get("baggage")
117124
require.Len(t, baggage, 1)
118-
assert.Equal(t, "key1=value1,key2=value2", baggage[0])
125+
assert.Equal(t, baggageVal, baggage[0])
119126
})
120127

121128
t.Run("invalid baggage header", func(t *testing.T) {

tests/integration/suite/daprd/tracing/baggage/http.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,19 @@ type httpBaggage struct {
4040
httpapp *prochttp.HTTP
4141
daprd *daprd.Daprd
4242

43-
baggage atomic.Bool
43+
baggage atomic.Bool
44+
baggageVals atomic.Value
4445
}
4546

4647
func (h *httpBaggage) Setup(t *testing.T) []framework.Option {
4748
handler := http.NewServeMux()
4849
handler.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
49-
if baggage := r.Header.Get("baggage"); baggage != "" {
50+
if baggage := r.Header.Values("baggage"); len(baggage) > 0 {
5051
h.baggage.Store(true)
52+
h.baggageVals.Store(strings.Join(baggage, ","))
5153
} else {
5254
h.baggage.Store(false)
55+
h.baggageVals.Store("")
5356
}
5457
w.Write([]byte(`OK`))
5558
})
@@ -76,6 +79,7 @@ func (h *httpBaggage) Run(t *testing.T, ctx context.Context) {
7679
defer appresp.Body.Close()
7780
assert.Equal(t, http.StatusOK, appresp.StatusCode)
7881
assert.False(t, h.baggage.Load())
82+
assert.Equal(t, "", h.baggageVals.Load())
7983
})
8084

8185
t.Run("baggage header provided", func(t *testing.T) {
@@ -84,16 +88,18 @@ func (h *httpBaggage) Run(t *testing.T, ctx context.Context) {
8488
appreq, err := http.NewRequestWithContext(t.Context(), http.MethodPost, appURL, strings.NewReader("{\"operation\":\"get\"}"))
8589
require.NoError(t, err)
8690

87-
appreq.Header.Set("baggage", "key1=value1,key2=value2")
91+
baggageVal := "key1=value1,key2=value2"
92+
appreq.Header.Set("baggage", baggageVal)
8893

8994
appresp, err := httpClient.Do(appreq)
9095
require.NoError(t, err)
9196
defer appresp.Body.Close()
9297
assert.Equal(t, http.StatusOK, appresp.StatusCode)
9398
assert.True(t, h.baggage.Load())
99+
assert.Equal(t, baggageVal, h.baggageVals.Load())
94100

95101
// Verify baggage header is in response
96-
assert.Equal(t, "key1=value1,key2=value2", appresp.Header.Get("baggage"))
102+
assert.Equal(t, baggageVal, appresp.Header.Get("baggage"))
97103
})
98104

99105
t.Run("invalid baggage header", func(t *testing.T) {

0 commit comments

Comments
 (0)