Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add idle_timeout to fn tool #663

Merged
merged 7 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ dep:
build:
go build -o functions

test:
clean-db:
rm -f /tmp/bolt_fn_*.db

test: clean-db
go test -v $(shell go list ./... | grep -v vendor | grep -v examples | grep -v tool | grep -v fn)
cd fn && $(MAKE) test

test-tag:
test-tag: clean-db
go test -v $(shell go list ./... | grep -v vendor | grep -v examples | grep -v tool | grep -v fn) -tags=$(TAG)

test-datastore:
Expand Down
2 changes: 1 addition & 1 deletion api/datastore/bolt/bolt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/iron-io/functions/api/datastore/internal/datastoretest"
)

const tmpBolt = "/tmp/func_test_bolt.db"
const tmpBolt = "/tmp/bolt_fn_test.db"

func TestDatastore(t *testing.T) {
u, err := url.Parse("bolt://" + tmpBolt)
Expand Down
69 changes: 61 additions & 8 deletions api/server/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"fmt"
"os"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -47,8 +48,8 @@ func teardown() {
}

func TestIntegration(t *testing.T) {
DB_FILE = "/tmp/bolt.db"
MQ_FILE = "/tmp/bolt_mq.db"
DB_FILE = "/tmp/bolt_fn_db.db"
MQ_FILE = "/tmp/bolt_fn_mq.db"
PORT = 8080
API_URL = "http://localhost:8080"
setupServer()
Expand All @@ -59,8 +60,8 @@ func TestIntegration(t *testing.T) {

func TestIntegrationWithAuth(t *testing.T) {
viper.Set("jwt_auth_key", "test")
DB_FILE = "/tmp/bolt_auth.db"
MQ_FILE = "/tmp/bolt_auth_mq.db"
DB_FILE = "/tmp/bolt_fn_auth_db.db"
MQ_FILE = "/tmp/bolt_fn_auth_mq.db"
PORT = 8081
API_URL = "http://localhost:8081"
setupServer()
Expand Down Expand Up @@ -95,9 +96,29 @@ func testIntegration(t *testing.T) {
t.Error("fn apps create failed. - name doesnt match")
}

routeConfig := models.Route{
Path: "/new-route",
JwtKey: "route_key",
Image: "iron/hello",
Memory: 72,
Type: "sync",
Format: "http",
MaxConcurrency: 15,
Timeout: 65,
IdleTimeout: 55}

// Test create route

err = fn.Run([]string{"fn", "routes", "c", "test", "/new-route", "--jwt-key", "route_key"})
err = fn.Run([]string{"fn", "routes", "c", "test", routeConfig.Path,
"--jwt-key", routeConfig.JwtKey,
"--image", routeConfig.Image,
"--memory", strconv.Itoa(int(routeConfig.Memory)),
"--type", routeConfig.Type,
"--format", routeConfig.Format,
"--max-concurrency", strconv.Itoa(int(routeConfig.MaxConcurrency)),
"--timeout", strconv.Itoa(int(routeConfig.Timeout)) + "s",
"--idle-timeout", strconv.Itoa(int(routeConfig.IdleTimeout)) + "s"})

if err != nil {
t.Error(err)
}
Expand All @@ -109,20 +130,52 @@ func testIntegration(t *testing.T) {
t.Error("fn routes create failed.")
}

if routes[0].Path != "/new-route" {
if routes[0].Path != routeConfig.Path {
t.Error("fn routes create failed. - path doesnt match")
}

if routes[0].Image != routeConfig.Image {
t.Error("fn routes create failed. - image doesnt match")
}

if routes[0].Memory != routeConfig.Memory {
t.Error("fn routes create failed. - memory doesnt match")
}

if routes[0].Type != routeConfig.Type {
t.Error("fn routes create failed. - type doesnt match")
}

if routes[0].Format != routeConfig.Format {
t.Error("fn routes create failed. - format doesnt match")
}

if routes[0].MaxConcurrency != routeConfig.MaxConcurrency {
t.Error("fn routes create failed. - max-concurrency doesnt match")
}

if routes[0].Timeout != routeConfig.Timeout {
t.Error("fn routes create failed. - timeout doesnt match")
}

if routes[0].IdleTimeout != routeConfig.IdleTimeout {
t.Error("fn routes create failed. - idle timeout doesnt match")
}

if routes[0].JwtKey != routeConfig.JwtKey {
t.Error("fn routes create failed. - jwt-key doesnt match")
}

// Test call route

err = fn.Run([]string{"fn", "routes", "call", "test", "/new-route"})
err = fn.Run([]string{"fn", "routes", "call", "test", routeConfig.Path})
if err != nil {
t.Error(err)
}

// Test delete route

err = fn.Run([]string{"fn", "routes", "delete", "test", "/new-route"})
err = fn.Run([]string{"fn", "routes", "delete", "test", routeConfig.Path})
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/iron-io/functions/api/server/internal/routecache"
)

var tmpBolt = "/tmp/func_test_bolt.db"
var tmpBolt = "/tmp/bolt_fn_server.db"

type Suite []struct {
name string
Expand Down
16 changes: 16 additions & 0 deletions fn/commands/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ var routeFlags = []cli.Flag{
Name: "timeout",
Usage: "route timeout (eg. 30s)",
},
cli.DurationFlag{
Name: "idle-timeout",
Usage: "hot func timeout (eg. 30s)",
},
}

func Routes() cli.Command {
Expand Down Expand Up @@ -314,6 +318,11 @@ func routeWithFlags(c *cli.Context, rt *models.Route) {
rt.Timeout = &to
}

if t := c.Duration("idle-timeout"); t > 0 {
to := int64(t.Seconds())
rt.IDLETimeout = &to
}

if j := c.String("jwt-key"); j != "" {
rt.JwtKey = j
}
Expand Down Expand Up @@ -348,6 +357,10 @@ func routeWithFuncFile(c *cli.Context, rt *models.Route) {
to := int64(ff.Timeout.Seconds())
rt.Timeout = &to
}
if ff.IDLETimeout != nil {
to := int64(ff.IDLETimeout.Seconds())
rt.IDLETimeout = &to
}
if ff.JwtKey != nil && *ff.JwtKey != "" {
rt.JwtKey = *ff.JwtKey
}
Expand Down Expand Up @@ -466,6 +479,9 @@ func (a *routesCmd) patchRoute(appName, routePath string, r *fnmodels.Route) err
if r.Timeout != nil {
resp.Payload.Route.Timeout = r.Timeout
}
if r.IDLETimeout != nil {
resp.Payload.Route.IDLETimeout = r.IDLETimeout
}
if r.JwtKey != "" {
resp.Payload.Route.JwtKey = r.JwtKey
}
Expand Down
1 change: 1 addition & 0 deletions fn/common/funcfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Funcfile struct {
Memory *int64 `yaml:"memory,omitempty" json:"memory,omitempty"`
Format *string `yaml:"format,omitempty" json:"format,omitempty"`
Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`
IDLETimeout *time.Duration `yaml:"idle_timeout,omitempty" json:"idle_timeout,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: I think IdleTimeout is better than IDLETimeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but unfortunately it is defined as IDLETimeout in functions_go (which is auto generated). I am not sure why it capitalizes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so it's no problem.
Thanks 👍

Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
Config map[string]string `yaml:"config,omitempty" json:"config,omitempty"`
Build []string `yaml:"build,omitempty" json:"build,omitempty"`
Expand Down