Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zealws committed May 24, 2016
1 parent b4acb24 commit 36093f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/daemon/atcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (atcd *Atcd) CreateGroup(member string) (*atc_thrift.ShapingGroup, error) {
return nil, err
}
grp.ID = dbgrp.id
defer atcd.Cleanup()
return grp, nil
}

Expand Down Expand Up @@ -222,6 +223,7 @@ func (atcd *Atcd) JoinGroup(id int64, to_add, token string) error {
if err := atcd.shaper.JoinGroup(id, tgt); err != nil {
return err
}
defer atcd.Cleanup()
return err
}

Expand Down Expand Up @@ -250,8 +252,7 @@ func (atcd *Atcd) LeaveGroup(id int64, to_remove, token string) error {
if err := atcd.shaper.LeaveGroup(id, tgt); err != nil {
return err
}
// FIXME: clean shaper's group too!
defer atcd.db.Cleanup()
defer atcd.Cleanup()
return atcd.db.DeleteMember(tgt)
}

Expand Down Expand Up @@ -318,6 +319,10 @@ func (atcd *Atcd) otp(group *DbGroup) *otp.TOTP {
}
}

func (atcd *Atcd) Cleanup() {
atcd.db.Cleanup()
}

func makeSecret() string {
// Can probably find a better source of random secrets than this...
return uuid.New()
Expand Down
6 changes: 2 additions & 4 deletions src/daemon/atcd_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package daemon

import (
"runtime"
"testing"
"time"

"github.com/facebook/augmented-traffic-control/src/atc_thrift"
"github.com/facebook/augmented-traffic-control/src/shaping"
Expand Down Expand Up @@ -46,15 +46,13 @@ func TestAtcdLeaveGroup(_t *testing.T) {
}

func TestAtcdCleansEmptyGroups(_t *testing.T) {
_t.Skip("something changed with how goroutines were run and this is broken in 1.6. Deferring fixing until we refactor the cleanup logic")
t := Setup(_t, true)
defer t.Cleanup()
grp := t.CreateGroup("1.2.3.4")
token := t.token(grp)
t.LeaveGroup(grp.ID, "1.2.3.4", token)

// Allow other goroutines to run
runtime.Gosched()
time.Sleep(1 * time.Millisecond)

grp, err := t.atcd.GetGroup(grp.ID)
if err != NoSuchItem {
Expand Down

0 comments on commit 36093f6

Please sign in to comment.