-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide option to timeout functions earlier than configured
A header of X-Timeout can be passed to reduce the value of exec_timeout. The consumer invoking the function is responsible for tuning this value and making sure it has enough headroom. The change was requested by @kevin-lindsay-1 for functions which process batched data of varying size and could run for 24 hours or 2 minutes, but need to timeout in a timely fashion, according to the input. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
- Loading branch information
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package executor | ||
|
||
import ( | ||
"net/http/httptest" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestGetTimeout_PicksLowerOverride(t *testing.T) { | ||
override := time.Second * 10 | ||
r := httptest.NewRequest("GET", "http://localhost:8080", nil) | ||
r.Header.Add("X-Timeout", override.Round(time.Second).String()) | ||
|
||
defaultTimeout := time.Second * 20 | ||
got := getTimeout(r, defaultTimeout) | ||
want := time.Second * 10 | ||
|
||
if got != want { | ||
t.Errorf("getTimeout() got: %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func TestGetTimeout_CapsOverrideToDefaultValue(t *testing.T) { | ||
override := time.Second * 21 | ||
r := httptest.NewRequest("GET", "http://localhost:8080", nil) | ||
r.Header.Add("X-Timeout", override.Round(time.Second).String()) | ||
|
||
defaultTimeout := time.Second * 20 | ||
got := getTimeout(r, defaultTimeout) | ||
want := time.Second * 20 | ||
|
||
if got != want { | ||
t.Errorf("getTimeout() got: %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func TestGetTimeout_NoDefaultMeansNoOverride(t *testing.T) { | ||
override := time.Second * 10 | ||
r := httptest.NewRequest("GET", "http://localhost:8080", nil) | ||
r.Header.Add("X-Timeout", override.Round(time.Second).String()) | ||
|
||
defaultTimeout := time.Nanosecond * 0 | ||
got := getTimeout(r, defaultTimeout) | ||
want := time.Nanosecond * 0 | ||
|
||
if got != want { | ||
t.Errorf("getTimeout() got: %v, want %v", got, want) | ||
} | ||
} |