mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #38739 from foxyriver/close
Automatic merge from submit-queue Object r repeat close **What this PR does / why we need it**: Object r repeat close. each end of the for loop, the object r has been closed. so omitting defer r.close(), to avoid repeat close. **Special notes for your reviewer**: **Release note**: ```release-note ```
This commit is contained in:
commit
9bd1b90c33
@ -299,68 +299,68 @@ func TestWatchRead(t *testing.T) {
|
|||||||
|
|
||||||
for _, protocol := range protocols {
|
for _, protocol := range protocols {
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
info, ok := runtime.SerializerInfoForMediaType(api.Codecs.SupportedMediaTypes(), test.MediaType)
|
func() {
|
||||||
if !ok || info.StreamSerializer == nil {
|
info, ok := runtime.SerializerInfoForMediaType(api.Codecs.SupportedMediaTypes(), test.MediaType)
|
||||||
t.Fatal(info)
|
if !ok || info.StreamSerializer == nil {
|
||||||
}
|
t.Fatal(info)
|
||||||
streamSerializer := info.StreamSerializer
|
}
|
||||||
|
streamSerializer := info.StreamSerializer
|
||||||
|
|
||||||
r, contentType := protocol.fn(test.Accept)
|
r, contentType := protocol.fn(test.Accept)
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
if contentType != "__default__" && contentType != test.ExpectedContentType {
|
if contentType != "__default__" && contentType != test.ExpectedContentType {
|
||||||
t.Errorf("Unexpected content type: %#v", contentType)
|
t.Errorf("Unexpected content type: %#v", contentType)
|
||||||
}
|
}
|
||||||
objectCodec := api.Codecs.DecoderToVersion(info.Serializer, testInternalGroupVersion)
|
objectCodec := api.Codecs.DecoderToVersion(info.Serializer, testInternalGroupVersion)
|
||||||
|
|
||||||
var fr io.ReadCloser = r
|
var fr io.ReadCloser = r
|
||||||
if !protocol.selfFraming {
|
if !protocol.selfFraming {
|
||||||
fr = streamSerializer.Framer.NewFrameReader(r)
|
fr = streamSerializer.Framer.NewFrameReader(r)
|
||||||
}
|
}
|
||||||
d := streaming.NewDecoder(fr, streamSerializer.Serializer)
|
d := streaming.NewDecoder(fr, streamSerializer.Serializer)
|
||||||
|
|
||||||
var w *watch.FakeWatcher
|
var w *watch.FakeWatcher
|
||||||
for w == nil {
|
for w == nil {
|
||||||
w = simpleStorage.Watcher()
|
w = simpleStorage.Watcher()
|
||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, item := range podWatchTestTable {
|
for i, item := range podWatchTestTable {
|
||||||
action, object := item.t, item.obj
|
action, object := item.t, item.obj
|
||||||
name := fmt.Sprintf("%s-%s-%d", protocol.name, test.MediaType, i)
|
name := fmt.Sprintf("%s-%s-%d", protocol.name, test.MediaType, i)
|
||||||
|
|
||||||
|
// Send
|
||||||
|
w.Action(action, object)
|
||||||
|
// Test receive
|
||||||
|
var got metav1.WatchEvent
|
||||||
|
_, _, err := d.Decode(nil, &got)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s: Unexpected error: %v", name, err)
|
||||||
|
}
|
||||||
|
if got.Type != string(action) {
|
||||||
|
t.Errorf("%s: Unexpected type: %v", name, got.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
gotObj, err := runtime.Decode(objectCodec, got.Object.Raw)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s: Decode error: %v", name, err)
|
||||||
|
}
|
||||||
|
if _, err := api.GetReference(gotObj); err != nil {
|
||||||
|
t.Errorf("%s: Unable to construct reference: %v", name, err)
|
||||||
|
}
|
||||||
|
if e, a := object, gotObj; !api.Semantic.DeepEqual(e, a) {
|
||||||
|
t.Errorf("%s: different: %s", name, diff.ObjectDiff(e, a))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.Stop()
|
||||||
|
|
||||||
// Send
|
|
||||||
w.Action(action, object)
|
|
||||||
// Test receive
|
|
||||||
var got metav1.WatchEvent
|
var got metav1.WatchEvent
|
||||||
_, _, err := d.Decode(nil, &got)
|
_, _, err := d.Decode(nil, &got)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Fatalf("%s: Unexpected error: %v", name, err)
|
t.Errorf("Unexpected non-error")
|
||||||
}
|
}
|
||||||
if got.Type != string(action) {
|
}()
|
||||||
t.Errorf("%s: Unexpected type: %v", name, got.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
gotObj, err := runtime.Decode(objectCodec, got.Object.Raw)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%s: Decode error: %v", name, err)
|
|
||||||
}
|
|
||||||
if _, err := api.GetReference(gotObj); err != nil {
|
|
||||||
t.Errorf("%s: Unable to construct reference: %v", name, err)
|
|
||||||
}
|
|
||||||
if e, a := object, gotObj; !api.Semantic.DeepEqual(e, a) {
|
|
||||||
t.Errorf("%s: different: %s", name, diff.ObjectDiff(e, a))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.Stop()
|
|
||||||
|
|
||||||
var got metav1.WatchEvent
|
|
||||||
_, _, err := d.Decode(nil, &got)
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("Unexpected non-error")
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user