mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
Fix flaky TestOpGet and TestSyncCreateTimeout
This commit is contained in:
parent
c372b74bc8
commit
f220aa1aba
@ -586,7 +586,7 @@ func expectApiStatus(t *testing.T, method, url string, data []byte, code int) *a
|
|||||||
|
|
||||||
func TestErrorsToAPIStatus(t *testing.T) {
|
func TestErrorsToAPIStatus(t *testing.T) {
|
||||||
cases := map[error]api.Status{
|
cases := map[error]api.Status{
|
||||||
NewAlreadyExistsErr("foo", "bar"): api.Status{
|
NewAlreadyExistsErr("foo", "bar"): {
|
||||||
Status: api.StatusFailure,
|
Status: api.StatusFailure,
|
||||||
Code: http.StatusConflict,
|
Code: http.StatusConflict,
|
||||||
Reason: "already_exists",
|
Reason: "already_exists",
|
||||||
@ -596,7 +596,7 @@ func TestErrorsToAPIStatus(t *testing.T) {
|
|||||||
ID: "bar",
|
ID: "bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
NewConflictErr("foo", "bar", errors.New("failure")): api.Status{
|
NewConflictErr("foo", "bar", errors.New("failure")): {
|
||||||
Status: api.StatusFailure,
|
Status: api.StatusFailure,
|
||||||
Code: http.StatusConflict,
|
Code: http.StatusConflict,
|
||||||
Reason: "conflict",
|
Reason: "conflict",
|
||||||
@ -719,9 +719,12 @@ func TestWriteRAWJSONMarshalError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncCreateTimeout(t *testing.T) {
|
func TestSyncCreateTimeout(t *testing.T) {
|
||||||
|
testOver := make(chan struct{})
|
||||||
|
defer close(testOver)
|
||||||
storage := SimpleRESTStorage{
|
storage := SimpleRESTStorage{
|
||||||
injectedFunction: func(obj interface{}) (interface{}, error) {
|
injectedFunction: func(obj interface{}) (interface{}, error) {
|
||||||
time.Sleep(5 * time.Millisecond)
|
// Eliminate flakes by ensuring the create operation takes longer than this test.
|
||||||
|
<-testOver
|
||||||
return obj, nil
|
return obj, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,15 @@ func TestOperationsList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestOpGet(t *testing.T) {
|
func TestOpGet(t *testing.T) {
|
||||||
simpleStorage := &SimpleRESTStorage{}
|
testOver := make(chan struct{})
|
||||||
|
defer close(testOver)
|
||||||
|
simpleStorage := &SimpleRESTStorage{
|
||||||
|
injectedFunction: func(obj interface{}) (interface{}, error) {
|
||||||
|
// Eliminate flakes by ensuring the create operation takes longer than this test.
|
||||||
|
<-testOver
|
||||||
|
return obj, nil
|
||||||
|
},
|
||||||
|
}
|
||||||
handler := New(map[string]RESTStorage{
|
handler := New(map[string]RESTStorage{
|
||||||
"foo": simpleStorage,
|
"foo": simpleStorage,
|
||||||
}, codec, "/prefix/version")
|
}, codec, "/prefix/version")
|
||||||
|
Loading…
Reference in New Issue
Block a user