Merge lp:~elopio/snappy/test_go_xkcd into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 582
Merged at revision: 582
Proposed branch: lp:~elopio/snappy/test_go_xkcd
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~elopio/snappy/test_go_install_framework
Diff against target: 99 lines (+29/-21)
2 files modified
_integration-tests/tests/11_test_xkcd_listens (+0/-15)
_integration-tests/tests/latest/installApp_test.go (+29/-6)
To merge this branch: bzr merge lp:~elopio/snappy/test_go_xkcd
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve
Review via email: mp+264668@code.launchpad.net

Commit message

Translate the xkcd test to go.

To post a comment you must log in.
Revision history for this message
Federico Gimenez (fgimenez) wrote :

Looks very good! A couple of comments, being the one related to s.SnappySuite.TearDownTest(c) the only important thing.

Cheers!

Revision history for this message
Leo Arias (elopio) wrote :

replied. Thanks for the review, a new version coming soon. Please check my reply to TearDownTest.

Revision history for this message
Federico Gimenez (fgimenez) wrote :

You are totally right about the anonymous struct members, I can even see this in the test output:

START: <autogenerated>:8: installAppSuite.TearDownTest
sudo snappy remove xkcd-webserver.canonical
Removing xkcd-webserver.canonical
PASS: <autogenerated>:8: installAppSuite.TearDownTest 0.370s

So please forget what I said :D

Revision history for this message
Leo Arias (elopio) wrote :

I removed the sleep and it failed. But the systemd service is running, the problem is that it takes some time between the service starting (i.e., the main method being run) and the port to be ready and listening. So we could poll for the port 80 to be ready, that is for http.Get("http://localhost") to return no error.
I found this nice example with the ticker http://3.bp.blogspot.com/-XzfNd-eL6zc/VVq6Im6XmpI/AAAAAAAAGvM/DuSXnY3dzUg/s1600/Screenshot%2Bfrom%2B2015-05-19%2B00%3A20%3A33.png

But, as we only need one second tops, it will tick only once. Or we could make the ticks smaller, but in this test waiting less than a second doesn't change anything.

So I left the sleep for simplicity, but reported a bug so we can remove it at some point.

Revision history for this message
Federico Gimenez (fgimenez) wrote :

Great, thanks! The ticker looks very good :)

Perhaps we could try to bundle the logic for making sure that the service is installed (whatever it is) in our first checker, something like IsServiceInstalled (also another for snaps?) or IsServiceRunning, we can talk later about that.

Cheers!

review: Approve
Revision history for this message
Leo Arias (elopio) wrote :

ok, I'm starting to miss custom checkers, so yes, lets see how to add some.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file '_integration-tests/tests/11_test_xkcd_listens'
2--- _integration-tests/tests/11_test_xkcd_listens 2015-06-15 15:36:29 +0000
3+++ _integration-tests/tests/11_test_xkcd_listens 1970-01-01 00:00:00 +0000
4@@ -1,15 +0,0 @@
5-test() {
6- # FIXME: add $SNAPPY search webserver
7-
8- sudo $SNAPPY install xkcd-webserver.canonical
9-
10- # FIXME: sucks, needed because "systemctl start" does not
11- # wait until the service is really started
12- sleep 1
13-
14- T="HTTP/1.0 200 OK"
15- TEMPF=$(tempfile)
16- printf "GET / HTTP/1.0\n\n"|nc localhost 80 > $TEMPF
17- test_regexp "$T" cat $TEMPF
18- rm -f $TEMPF
19-}
20
21=== modified file '_integration-tests/tests/latest/installApp_test.go'
22--- _integration-tests/tests/latest/installApp_test.go 2015-07-14 16:37:32 +0000
23+++ _integration-tests/tests/latest/installApp_test.go 2015-07-14 16:37:32 +0000
24@@ -20,7 +20,9 @@
25 package latest
26
27 import (
28+ "net/http"
29 "os/exec"
30+ "time"
31
32 . "../common"
33
34@@ -33,14 +35,11 @@
35 SnappySuite
36 }
37
38-func (s *installAppSuite) TearDownTest(c *check.C) {
39- RemoveSnap(c, "hello-world")
40- // run cleanup last
41- s.SnappySuite.TearDownTest(c)
42-}
43-
44 func (s *installAppSuite) TestInstallAppMustPrintPackageInformation(c *check.C) {
45 installOutput := InstallSnap(c, "hello-world")
46+ s.AddCleanup(func() {
47+ RemoveSnap(c, "hello-world")
48+ })
49
50 expected := "(?ms)" +
51 "Installing hello-world\n" +
52@@ -54,6 +53,9 @@
53
54 func (s *installAppSuite) TestCallBinaryFromInstalledSnap(c *check.C) {
55 InstallSnap(c, "hello-world")
56+ s.AddCleanup(func() {
57+ RemoveSnap(c, "hello-world")
58+ })
59
60 echoOutput := ExecCommand(c, "hello-world.echo")
61
62@@ -62,6 +64,9 @@
63
64 func (s *installAppSuite) TestCallBinaryWithPermissionDeniedMustPrintError(c *check.C) {
65 InstallSnap(c, "hello-world")
66+ s.AddCleanup(func() {
67+ RemoveSnap(c, "hello-world")
68+ })
69
70 cmd := exec.Command("hello-world.evil")
71 echoOutput, err := cmd.CombinedOutput()
72@@ -80,9 +85,27 @@
73
74 func (s *installAppSuite) TestInfoMustPrintInstalledPackageInformation(c *check.C) {
75 InstallSnap(c, "hello-world")
76+ s.AddCleanup(func() {
77+ RemoveSnap(c, "hello-world")
78+ })
79
80 infoOutput := ExecCommand(c, "snappy", "info")
81
82 expected := "(?ms).*^apps: hello-world\n"
83 c.Assert(infoOutput, check.Matches, expected)
84 }
85+
86+func (s *installAppSuite) TestAppNetworkingServiceMustBeStarted(c *check.C) {
87+ InstallSnap(c, "xkcd-webserver.canonical")
88+ s.AddCleanup(func() {
89+ RemoveSnap(c, "xkcd-webserver.canonical")
90+ })
91+
92+ // FIXME: sucks, needed because "systemctl start" does not wait until the
93+ // port is listening. https://bugs.launchpad.net/snappy/+bug/1474463
94+ time.Sleep(1 * time.Second)
95+ resp, err := http.Get("http://localhost")
96+ c.Assert(err, check.IsNil)
97+ c.Check(resp.Status, check.Equals, "200 OK")
98+ c.Assert(resp.Proto, check.Equals, "HTTP/1.0")
99+}

Subscribers

People subscribed via source and target branches