Merge pull request #90496 from gaurav1086/test_decoder_race_condition

Fix race condition in decoder test

Kubernetes-commit: 6ed5290729aeb0aacd2c7ad6f6f49ae6212e4762
This commit is contained in:
Kubernetes Publisher 2020-05-19 20:34:46 -07:00
commit c4288707f0

View File

@ -48,16 +48,16 @@ func TestDecoder(t *testing.T) {
out, in := io.Pipe()
decoder := restclientwatch.NewDecoder(streaming.NewDecoder(out, getDecoder()), getDecoder())
expect := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
encoder := json.NewEncoder(in)
eType := eventType
go func() {
data, err := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), expect)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
event := metav1.WatchEvent{
Type: string(eventType),
Type: string(eType),
Object: runtime.RawExtension{Raw: json.RawMessage(data)},
}
if err := encoder.Encode(&event); err != nil {
@ -72,7 +72,7 @@ func TestDecoder(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
if e, a := eventType, action; e != a {
if e, a := eType, action; e != a {
t.Errorf("Expected %v, got %v", e, a)
}
if e, a := expect, got; !apiequality.Semantic.DeepDerivative(e, a) {