mirror of https://github.com/k3s-io/k3s
Merge pull request #683 from smarterclayton/slightly_pause_on_return
Slightly pause on requests to allow most to finishpull/6/head
commit
76e2cd70f7
|
@ -59,10 +59,11 @@ func NewNotFoundErr(kind, name string) error {
|
||||||
//
|
//
|
||||||
// TODO: consider migrating this to go-restful which is a more full-featured version of the same thing.
|
// TODO: consider migrating this to go-restful which is a more full-featured version of the same thing.
|
||||||
type APIServer struct {
|
type APIServer struct {
|
||||||
prefix string
|
prefix string
|
||||||
storage map[string]RESTStorage
|
storage map[string]RESTStorage
|
||||||
ops *Operations
|
ops *Operations
|
||||||
mux *http.ServeMux
|
mux *http.ServeMux
|
||||||
|
asyncOpWait time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new APIServer object.
|
// New creates a new APIServer object.
|
||||||
|
@ -74,6 +75,8 @@ func New(storage map[string]RESTStorage, prefix string) *APIServer {
|
||||||
prefix: strings.TrimRight(prefix, "/"),
|
prefix: strings.TrimRight(prefix, "/"),
|
||||||
ops: NewOperations(),
|
ops: NewOperations(),
|
||||||
mux: http.NewServeMux(),
|
mux: http.NewServeMux(),
|
||||||
|
// Delay just long enough to handle most simple write operations
|
||||||
|
asyncOpWait: time.Millisecond * 25,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Primary API methods
|
// Primary API methods
|
||||||
|
@ -279,6 +282,8 @@ func (s *APIServer) createOperation(out <-chan interface{}, sync bool, timeout t
|
||||||
op := s.ops.NewOperation(out)
|
op := s.ops.NewOperation(out)
|
||||||
if sync {
|
if sync {
|
||||||
op.WaitFor(timeout)
|
op.WaitFor(timeout)
|
||||||
|
} else if s.asyncOpWait != 0 {
|
||||||
|
op.WaitFor(s.asyncOpWait)
|
||||||
}
|
}
|
||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,6 +396,7 @@ func TestCreate(t *testing.T) {
|
||||||
handler := New(map[string]RESTStorage{
|
handler := New(map[string]RESTStorage{
|
||||||
"foo": simpleStorage,
|
"foo": simpleStorage,
|
||||||
}, "/prefix/version")
|
}, "/prefix/version")
|
||||||
|
handler.asyncOpWait = 0
|
||||||
server := httptest.NewServer(handler)
|
server := httptest.NewServer(handler)
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ func TestOpGet(t *testing.T) {
|
||||||
handler := New(map[string]RESTStorage{
|
handler := New(map[string]RESTStorage{
|
||||||
"foo": simpleStorage,
|
"foo": simpleStorage,
|
||||||
}, "/prefix/version")
|
}, "/prefix/version")
|
||||||
|
handler.asyncOpWait = 0
|
||||||
server := httptest.NewServer(handler)
|
server := httptest.NewServer(handler)
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue