From 511b36bd435da84a40d5b3a1da6819237817fd7d Mon Sep 17 00:00:00 2001 From: Jared Folkins Date: Tue, 20 Jan 2015 17:03:08 -0800 Subject: [PATCH] enhc: removing sleep() from tests --- action_test.go | 5 ++--- director.go | 4 ++++ director_test.go | 8 +++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/action_test.go b/action_test.go index 279591f..4612998 100644 --- a/action_test.go +++ b/action_test.go @@ -107,9 +107,8 @@ func TestActionWhenTimeServed(t *testing.T) { t.Errorf("whenTimeServedCounter should be 0 instead", whenTimeServedCounter) } - dur := time.Duration(time.Second * 1) - - time.Sleep(dur) + dur := time.Now().Add(-time.Hour * 1) + a.jails[rn].releaseBy = dur for _, j := range a.jails { a.timeServed(j) diff --git a/director.go b/director.go index c6d52bd..d22a002 100644 --- a/director.go +++ b/director.go @@ -277,3 +277,7 @@ func (d *Director) timeToLive(an string) time.Time { func (d *Director) keepAlive(an string) { d.actors[an].Value.(*Actor).rebaseAll() } + +func (d *Director) actor(an string) *Actor { + return d.actors[an].Value.(*Actor) +} diff --git a/director_test.go b/director_test.go index 2e3a5f8..5e7bd17 100644 --- a/director_test.go +++ b/director_test.go @@ -66,16 +66,22 @@ func TestDirectorlMaintenance(t *testing.T) { // MOCK STATE CHANGE // Remove 10 minutes from the world - a := d.actors[an].Value.(*Actor) + // get actor + a := d.actor(an) + // set time to be one hour ago dur := time.Now().Add(-time.Hour * 1) + // change time.Time of infraction and jail a.jails[r1n].releaseBy = dur a.infractions[r2n].expireBy = dur + // perform maintenance d.lMaintenance() + // change time to live a.ttl = dur + // perform maintenance d.lMaintenance() b = d.lInfractionExists(an, r2n)