コード例 #1
0
func TestWorker(t *testing.T) {
	tes := new(monitor.MonitoredWorker)
	itw := &TestWork{From: 1, To: 8, sleep: 300}
	tes.Itw = itw
	tes.Start()
	log.Println(tes.Start())
	time.Sleep(time.Second * 1)
	if tes.GetState() != 1 {
		t.Error("Expected Running(1)")
		return
	}
	tes.Stop()
	if tes.GetState() != 0 {
		t.Error("Expected Stoped(0)")
		return
	}
	tes.Start()
	time.Sleep(time.Second * 9)
	if tes.GetState() != 3 {
		t.Error("Expected Comlete(3)")
		return
	}

	tes.Start()
	time.Sleep(time.Second * 1)
	if tes.GetState() != 3 {
		t.Error("Expected Failed(3)")
		return
	}
}
コード例 #2
0
func TestPartDownloadWorker(t *testing.T) {
	return
	url := "http://releases.ubuntu.com/14.04.2/ubuntu-14.04.2-server-amd64.list"
	c, _ := httpclient.GetSize(url)
	c = c / 2
	f, _ := iotools.CreateSafeFile("g_ubuntu-14.04.2-server-amd64.list")
	defer f.Close()
	log.Println(f.Truncate(c))
	dow := httpclient.CreatePartialDownloader(url, f, 0, 0, c)
	mv := monitor.MonitoredWorker{Itw: dow}
	log.Println(mv.Start())
	log.Println(mv.Start())
	time.Sleep(time.Second * 1)
	log.Println(mv.Stop())
	time.Sleep(time.Second * 5)
	log.Println(mv.Start())
	log.Println(mv.Start())
	time.Sleep(time.Second * 5)
	log.Println(mv.Stop())
}