Example #1
0
// TestSimpleInactivityTimeout tests a simple scene usage
// with inactivity timeout.
func TestSimpleInactivityTimeout(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, false)
	scn := scene.StartLimited(100*time.Millisecond, 0)

	err := scn.Store("foo", 4711)
	assert.Nil(err)

	for i := 0; i < 5; i++ {
		foo, err := scn.Fetch("foo")
		assert.Nil(err)
		assert.Equal(foo, 4711)
		time.Sleep(50)
	}

	time.Sleep(100 * time.Millisecond)

	foo, err := scn.Fetch("foo")
	assert.True(scene.IsTimeoutError(err))
	assert.Nil(foo)

	status, err := scn.Status()
	assert.True(scene.IsTimeoutError(err))
	assert.Equal(status, scene.Over)

	err = scn.Stop()
	assert.True(scene.IsTimeoutError(err))
}
Example #2
0
// TestSimpleAbsoluteTimeout tests a simple scene usage
// with absolute timeout.
func TestSimpleAbsoluteTimeout(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, false)
	scn := scene.StartLimited(0, 250*time.Millisecond)

	err := scn.Store("foo", 4711)
	assert.Nil(err)

	for {
		_, err = scn.Fetch("foo")
		if err != nil {
			assert.True(scene.IsTimeoutError(err))
			break
		}
		time.Sleep(50)
	}

	err = scn.Stop()
	assert.True(scene.IsTimeoutError(err))
}
Example #3
0
// TestCleanupAfterTimeout tests the cleanup of props after
// a timeout.
func TestCleanupAfterTimeout(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, false)
	cleanups := make(map[string]interface{})
	cleanup := func(key string, prop interface{}) error {
		cleanups[key] = prop
		return nil
	}
	scn := scene.StartLimited(0, 100*time.Millisecond)

	err := scn.StoreClean("foo", 4711, cleanup)
	assert.Nil(err)
	err = scn.StoreClean("bar", "yadda", cleanup)
	assert.Nil(err)

	time.Sleep(250 * time.Millisecond)

	err = scn.Stop()
	assert.True(scene.IsTimeoutError(err))

	assert.Length(cleanups, 2)
	assert.Equal(cleanups["foo"], 4711)
	assert.Equal(cleanups["bar"], "yadda")
}