Skip to content

Commit

Permalink
Addressing issue with non-deterministic test as tailers are set based…
Browse files Browse the repository at this point in the history
… on the TailerMD, which is a map. The order a map is returned is non-deterministic.
  • Loading branch information
joshgarnett committed Apr 26, 2024
1 parent 3ab49ed commit 09f6892
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions runtime/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"reflect"
"sort"
"testing"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
Expand Down Expand Up @@ -542,7 +543,7 @@ func TestOutgoingTrailerMatcher(t *testing.T) {
headers: http.Header{
"Transfer-Encoding": []string{"chunked"},
"Content-Type": []string{"application/json"},
"Trailer": []string{"Grpc-Trailer-Foo", "Grpc-Trailer-Baz"},
"Trailer": []string{"Grpc-Trailer-Baz", "Grpc-Trailer-Foo"},
},
trailer: http.Header{
"Grpc-Trailer-Foo": []string{"bar"},
Expand Down Expand Up @@ -607,7 +608,7 @@ func TestOutgoingTrailerMatcher(t *testing.T) {
headers: http.Header{
"Transfer-Encoding": []string{"chunked"},
"Content-Type": []string{"application/json"},
"Trailer": []string{"Grpc-Trailer-Foo", "Grpc-Trailer-Baz"},
"Trailer": []string{"Grpc-Trailer-Baz", "Grpc-Trailer-Foo"},
"Etag": []string{"\"41bf5d28a47f59b2a649e44f2607b0ea\""},
},
trailer: http.Header{
Expand Down Expand Up @@ -679,6 +680,9 @@ func TestOutgoingTrailerMatcher(t *testing.T) {
t.Fatalf("StatusCode %d want %d", w.StatusCode, http.StatusOK)
}

// Sort to the trailer headers to ensure the test is deterministic
sort.Strings(w.Header["Trailer"])

if !reflect.DeepEqual(w.Header, tc.headers) {
t.Fatalf("Header %v want %v", w.Header, tc.headers)
}
Expand Down

0 comments on commit 09f6892

Please sign in to comment.