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
=== modified file 'client/client_test.go'
--- client/client_test.go 2014-04-16 18:09:47 +0000
+++ client/client_test.go 2014-04-18 11:28:27 +0000
@@ -177,7 +177,7 @@
177 c.Check(cli.idder, IsNil)177 c.Check(cli.idder, IsNil)
178 err := cli.configure()178 err := cli.configure()
179 c.Assert(err, IsNil)179 c.Assert(err, IsNil)
180 c.Assert(cli.idder, DeepEquals, identifier.New())180 c.Assert(cli.idder, FitsTypeOf, identifier.New())
181}181}
182182
183func (cs *clientSuite) TestConfigureSetsUpEndpoints(c *C) {183func (cs *clientSuite) TestConfigureSetsUpEndpoints(c *C) {
184184
=== modified file 'whoopsie/identifier/identifier.go'
--- whoopsie/identifier/identifier.go 2014-02-21 16:17:28 +0000
+++ whoopsie/identifier/identifier.go 2014-04-18 11:28:27 +0000
@@ -27,6 +27,7 @@
27import "C"27import "C"
28import "unsafe"28import "unsafe"
29import "errors"29import "errors"
30import "time"
3031
31// an Id knows how to generate itself, and how to stringify itself.32// an Id knows how to generate itself, and how to stringify itself.
32type Id interface {33type Id interface {
@@ -36,12 +37,17 @@
3637
37// Identifier is the default Id implementation.38// Identifier is the default Id implementation.
38type Identifier struct {39type Identifier struct {
39 value string40 value string
41 generator func(**C.char, **C.GError)
42}
43
44func generator(csp **C.char, errp **C.GError) {
45 C.whoopsie_identifier_generate(csp, errp)
40}46}
4147
42// New creates an Identifier, but does not call Generate() on it.48// New creates an Identifier, but does not call Generate() on it.
43func New() Id {49func New() Id {
44 return &Identifier{}50 return &Identifier{generator: generator}
45}51}
4652
47// Generate makes the Identifier create the identifier itself.53// Generate makes the Identifier create the identifier itself.
@@ -49,8 +55,18 @@
49 var gerr *C.GError55 var gerr *C.GError
50 var cs *C.char56 var cs *C.char
51 defer C.g_free((C.gpointer)(unsafe.Pointer(cs)))57 defer C.g_free((C.gpointer)(unsafe.Pointer(cs)))
52 C.whoopsie_identifier_generate(&cs, &gerr)58
5359 for i := 0; i < 200; i++ {
60 id.generator(&cs, &gerr)
61
62 if cs != nil || gerr != nil {
63 goto SuccessMaybe
64 }
65 time.Sleep(600 * time.Millisecond)
66 }
67 return errors.New("whoopsie_identifier_generate still bad after 2m; giving up")
68
69SuccessMaybe:
54 if gerr != nil {70 if gerr != nil {
55 return errors.New(C.GoString((*C.char)(gerr.message)))71 return errors.New(C.GoString((*C.char)(gerr.message)))
56 } else {72 } else {
5773
=== modified file 'whoopsie/identifier/identifier_test.go'
--- whoopsie/identifier/identifier_test.go 2014-01-15 15:51:50 +0000
+++ whoopsie/identifier/identifier_test.go 2014-04-18 11:28:27 +0000
@@ -41,3 +41,18 @@
41func (s *IdentifierSuite) TestIdentifierInterface(c *C) {41func (s *IdentifierSuite) TestIdentifierInterface(c *C) {
42 _ = []Id{New()}42 _ = []Id{New()}
43}43}
44
45// TestFailure checks that Identifier survives whoopsie shenanigans
46func (s *IdentifierSuite) TestIdentifierSurvivesShenanigans(c *C) {
47 count := 0
48 // using _Ctype* as a workaround for gocheck also having a C
49 gen := func(csp **_Ctype_char, errp **_Ctype_GError) {
50 count++
51 if count > 3 {
52 generator(csp, errp)
53 }
54 }
55 id := &Identifier{generator: gen}
56 id.Generate()
57 c.Check(id.String(), HasLen, 128)
58}

Subscribers

People subscribed via source and target branches