Merge lp:~chipaca/ubuntu-push/whoopsie-whoopsie-whoopsie into lp:ubuntu-push/automatic

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 133
Merged at revision: 132
Proposed branch: lp:~chipaca/ubuntu-push/whoopsie-whoopsie-whoopsie
Merge into: lp:ubuntu-push/automatic
Diff against target: 88 lines (+36/-5)
3 files modified
client/client_test.go (+1/-1)
whoopsie/identifier/identifier.go (+20/-4)
whoopsie/identifier/identifier_test.go (+15/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/whoopsie-whoopsie-whoopsie
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+216426@code.launchpad.net

Commit message

Loop whoopsie_identifier_generate until it starts working.

Description of the change

Loop whoopsie_identifier_generate until it starts working.

To post a comment you must log in.
Revision history for this message
Samuele Pedroni (pedronis) wrote :

looks good, given the behavior you are seeing I would even increase the sleep to 0.5s or 1s

review: Approve
133. By John Lenton

sleep a bit longer

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/client_test.go'
2--- client/client_test.go 2014-04-16 18:09:47 +0000
3+++ client/client_test.go 2014-04-18 11:28:27 +0000
4@@ -177,7 +177,7 @@
5 c.Check(cli.idder, IsNil)
6 err := cli.configure()
7 c.Assert(err, IsNil)
8- c.Assert(cli.idder, DeepEquals, identifier.New())
9+ c.Assert(cli.idder, FitsTypeOf, identifier.New())
10 }
11
12 func (cs *clientSuite) TestConfigureSetsUpEndpoints(c *C) {
13
14=== modified file 'whoopsie/identifier/identifier.go'
15--- whoopsie/identifier/identifier.go 2014-02-21 16:17:28 +0000
16+++ whoopsie/identifier/identifier.go 2014-04-18 11:28:27 +0000
17@@ -27,6 +27,7 @@
18 import "C"
19 import "unsafe"
20 import "errors"
21+import "time"
22
23 // an Id knows how to generate itself, and how to stringify itself.
24 type Id interface {
25@@ -36,12 +37,17 @@
26
27 // Identifier is the default Id implementation.
28 type Identifier struct {
29- value string
30+ value string
31+ generator func(**C.char, **C.GError)
32+}
33+
34+func generator(csp **C.char, errp **C.GError) {
35+ C.whoopsie_identifier_generate(csp, errp)
36 }
37
38 // New creates an Identifier, but does not call Generate() on it.
39 func New() Id {
40- return &Identifier{}
41+ return &Identifier{generator: generator}
42 }
43
44 // Generate makes the Identifier create the identifier itself.
45@@ -49,8 +55,18 @@
46 var gerr *C.GError
47 var cs *C.char
48 defer C.g_free((C.gpointer)(unsafe.Pointer(cs)))
49- C.whoopsie_identifier_generate(&cs, &gerr)
50-
51+
52+ for i := 0; i < 200; i++ {
53+ id.generator(&cs, &gerr)
54+
55+ if cs != nil || gerr != nil {
56+ goto SuccessMaybe
57+ }
58+ time.Sleep(600 * time.Millisecond)
59+ }
60+ return errors.New("whoopsie_identifier_generate still bad after 2m; giving up")
61+
62+SuccessMaybe:
63 if gerr != nil {
64 return errors.New(C.GoString((*C.char)(gerr.message)))
65 } else {
66
67=== modified file 'whoopsie/identifier/identifier_test.go'
68--- whoopsie/identifier/identifier_test.go 2014-01-15 15:51:50 +0000
69+++ whoopsie/identifier/identifier_test.go 2014-04-18 11:28:27 +0000
70@@ -41,3 +41,18 @@
71 func (s *IdentifierSuite) TestIdentifierInterface(c *C) {
72 _ = []Id{New()}
73 }
74+
75+// TestFailure checks that Identifier survives whoopsie shenanigans
76+func (s *IdentifierSuite) TestIdentifierSurvivesShenanigans(c *C) {
77+ count := 0
78+ // using _Ctype* as a workaround for gocheck also having a C
79+ gen := func(csp **_Ctype_char, errp **_Ctype_GError) {
80+ count++
81+ if count > 3 {
82+ generator(csp, errp)
83+ }
84+ }
85+ id := &Identifier{generator: gen}
86+ id.Generate()
87+ c.Check(id.String(), HasLen, 128)
88+}

Subscribers

People subscribed via source and target branches