Пример #1
0
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Daemon", func() {
	var adapter *fakestoreadapter.FakeStoreAdapter

	BeforeEach(func() {
		adapter = fakestoreadapter.New()
	})

	It("should call the function every PERIOD seconds, unless the function takes *longer* than PERIOD, and it should timeout when the function takes *too* long", func() {
		adapter.OnReleaseNodeChannel = func(releaseNodeChannel chan chan bool) {
			released := <-releaseNodeChannel
			released <- true
		}

		adapter.MaintainNodeStatus <- true

		callTimes := make(chan float64, 4)
		i := 0
		var startTime time.Time
		err := Daemonize("Daemon Test", func() error {
			if i == 0 {
				startTime = time.Now()
			}

			callTimes <- time.Since(startTime).Seconds()
			i += 1
			time.Sleep(time.Duration(i*10) * time.Millisecond)