Skip to content

Commit

Permalink
move timeout into its own package
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Nov 16, 2015
1 parent e05c220 commit 3623949
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
3 changes: 2 additions & 1 deletion daemon/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/ubuntu-core/snappy/release"
"github.com/ubuntu-core/snappy/snappy"
"github.com/ubuntu-core/snappy/systemd"
"github.com/ubuntu-core/snappy/timeout"
)

type apiSuite struct {
Expand Down Expand Up @@ -850,7 +851,7 @@ func (s *apiSuite) TestPackageServiceGet(c *check.C) {
m := rsp.Result.(map[string]*svcDesc)
c.Assert(m["svc"], check.FitsTypeOf, new(svcDesc))
c.Check(m["svc"].Op, check.Equals, "status")
c.Check(m["svc"].Spec, check.DeepEquals, &snappy.ServiceYaml{Name: "svc", StopTimeout: snappy.DefaultTimeout})
c.Check(m["svc"].Spec, check.DeepEquals, &snappy.ServiceYaml{Name: "svc", StopTimeout: timeout.DefaultTimeout})
c.Check(m["svc"].Status, check.DeepEquals, &snappy.PackageServiceStatus{ServiceName: "svc"})
}

Expand Down
13 changes: 7 additions & 6 deletions snappy/click_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/ubuntu-core/snappy/policy"
"github.com/ubuntu-core/snappy/progress"
"github.com/ubuntu-core/snappy/systemd"
"github.com/ubuntu-core/snappy/timeout"
)

func (s *SnapTestSuite) TestReadManifest(c *C) {
Expand Down Expand Up @@ -1251,7 +1252,7 @@ func (s *SnapTestSuite) TestSnappyGenerateSnapServiceTypeForking(c *C) {
Start: "bin/foo start",
Stop: "bin/foo stop",
PostStop: "bin/foo post-stop",
StopTimeout: DefaultTimeout,
StopTimeout: timeout.DefaultTimeout,
Description: "A fun webserver",
Forking: true,
}
Expand All @@ -1271,7 +1272,7 @@ func (s *SnapTestSuite) TestSnappyGenerateSnapServiceAppWrapper(c *C) {
Start: "bin/foo start",
Stop: "bin/foo stop",
PostStop: "bin/foo post-stop",
StopTimeout: DefaultTimeout,
StopTimeout: timeout.DefaultTimeout,
Description: "A fun webserver",
}
pkgPath := "/apps/xkcd-webserver.canonical/0.3.4/"
Expand All @@ -1290,7 +1291,7 @@ func (s *SnapTestSuite) TestSnappyGenerateSnapServiceAppWrapperWithExternalPort(
Start: "bin/foo start",
Stop: "bin/foo stop",
PostStop: "bin/foo post-stop",
StopTimeout: DefaultTimeout,
StopTimeout: timeout.DefaultTimeout,
Description: "A fun webserver",
Ports: &Ports{External: map[string]Port{"foo": Port{}}},
}
Expand All @@ -1310,7 +1311,7 @@ func (s *SnapTestSuite) TestSnappyGenerateSnapServiceFmkWrapper(c *C) {
Start: "bin/foo start",
Stop: "bin/foo stop",
PostStop: "bin/foo post-stop",
StopTimeout: DefaultTimeout,
StopTimeout: timeout.DefaultTimeout,
Description: "A fun webserver",
BusName: "foo.bar.baz",
}
Expand All @@ -1332,7 +1333,7 @@ func (s *SnapTestSuite) TestSnappyGenerateSnapServiceWrapperWhitelist(c *C) {
Start: "bin/foo start",
Stop: "bin/foo stop",
PostStop: "bin/foo post-stop",
StopTimeout: DefaultTimeout,
StopTimeout: timeout.DefaultTimeout,
Description: "A fun webserver\nExec=foo",
}
pkgPath := "/apps/xkcd-webserver.canonical/0.3.4/"
Expand Down Expand Up @@ -1570,7 +1571,7 @@ func (s *SnapTestSuite) TestSnappyGenerateSnapServiceWithSockte(c *C) {
Start: "bin/foo start",
Stop: "bin/foo stop",
PostStop: "bin/foo post-stop",
StopTimeout: DefaultTimeout,
StopTimeout: timeout.DefaultTimeout,
Description: "A fun webserver",
Socket: true,
}
Expand Down
15 changes: 8 additions & 7 deletions snappy/snapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/ubuntu-core/snappy/progress"
"github.com/ubuntu-core/snappy/release"
"github.com/ubuntu-core/snappy/systemd"
"github.com/ubuntu-core/snappy/timeout"
)

const (
Expand Down Expand Up @@ -122,12 +123,12 @@ type ServiceYaml struct {
Name string `yaml:"name" json:"name,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`

Start string `yaml:"start,omitempty" json:"start,omitempty"`
Stop string `yaml:"stop,omitempty" json:"stop,omitempty"`
PostStop string `yaml:"poststop,omitempty" json:"poststop,omitempty"`
StopTimeout Timeout `yaml:"stop-timeout,omitempty" json:"stop-timeout,omitempty"`
BusName string `yaml:"bus-name,omitempty" json:"bus-name,omitempty"`
Forking bool `yaml:"forking,omitempty" json:"forking,omitempty"`
Start string `yaml:"start,omitempty" json:"start,omitempty"`
Stop string `yaml:"stop,omitempty" json:"stop,omitempty"`
PostStop string `yaml:"poststop,omitempty" json:"poststop,omitempty"`
StopTimeout timeout.Timeout `yaml:"stop-timeout,omitempty" json:"stop-timeout,omitempty"`
BusName string `yaml:"bus-name,omitempty" json:"bus-name,omitempty"`
Forking bool `yaml:"forking,omitempty" json:"forking,omitempty"`

// set to yes if we need to create a systemd socket for this service
Socket bool `yaml:"socket,omitempty" json:"socket,omitempty"`
Expand Down Expand Up @@ -316,7 +317,7 @@ func parsePackageYamlData(yamlData []byte, hasConfig bool) (*packageYaml, error)

for i := range m.ServiceYamls {
if m.ServiceYamls[i].StopTimeout == 0 {
m.ServiceYamls[i].StopTimeout = DefaultTimeout
m.ServiceYamls[i].StopTimeout = timeout.DefaultTimeout
}
}

Expand Down
2 changes: 1 addition & 1 deletion snappy/timeout.go → timeout/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

package snappy
package timeout

import (
"encoding/json"
Expand Down
17 changes: 13 additions & 4 deletions snappy/timeout_test.go → timeout/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@
*
*/

package snappy
package timeout

import (
"encoding/json"
"testing"
"time"

. "gopkg.in/check.v1"
)

func (s *SnapTestSuite) TestTimeoutMarshal(c *C) {
// Hook up check.v1 into the "go test" runner
func Test(t *testing.T) { TestingT(t) }

type TimeoutTestSuite struct {
}

var _ = Suite(&TimeoutTestSuite{})

func (s *TimeoutTestSuite) TestTimeoutMarshal(c *C) {
bs, err := Timeout(DefaultTimeout).MarshalJSON()
c.Assert(err, IsNil)
c.Check(string(bs), Equals, `"30s"`)
Expand All @@ -36,13 +45,13 @@ type testT struct {
T Timeout
}

func (s *SnapTestSuite) TestTimeoutMarshalIndirect(c *C) {
func (s *TimeoutTestSuite) TestTimeoutMarshalIndirect(c *C) {
bs, err := json.Marshal(testT{DefaultTimeout})
c.Assert(err, IsNil)
c.Check(string(bs), Equals, `{"T":"30s"}`)
}

func (s *SnapTestSuite) TestTimeoutUnmarshal(c *C) {
func (s *TimeoutTestSuite) TestTimeoutUnmarshal(c *C) {
var t testT
c.Assert(json.Unmarshal([]byte(`{"T": "17ms"}`), &t), IsNil)
c.Check(t, DeepEquals, testT{T: Timeout(17 * time.Millisecond)})
Expand Down

0 comments on commit 3623949

Please sign in to comment.