示例#1
0
func TestNewCreateEventsAfterStartup(t *testing.T) {
	createChan := make(chan string, 10)
	deleteChan := make(chan string, 10)

	controlChan := make(chan bool, 1)

	tc := &testCattleClient{}

	go func() {
		va := volume.NewVolumeAgent(hc, socketFile, h, 5, tc, sp)
		err := va.Run(controlChan)
		if err != nil {
			t.Fatalf("Error starting convoy agent err=[%v]", err)
		}
	}()
	uuid1, err := createVolume("testVol1")
	if err != nil {
		t.Fatalf("Error while creating volume UUID=[%s] err=[%v]", uuid1, err)
	}
	defer deleteVolume(uuid1)

	go waitForCreateDeleteEvents(tc, createChan, deleteChan, controlChan)

	select {
	case vol := <-createChan:
		if vol != uuid1 {
			t.Errorf("Excpected uuid = [%s] but obtained uuid = [%s]", uuid1, vol)
		}
	case <-time.After(10 * time.Second):
		t.Fatal("Volume create event not detected")
	}
	uuid2, err := createVolume("testVol2")
	if err != nil {
		t.Fatalf("Error while creating volume UUID=[%s] err=[%v]", uuid2, err)
	}
	defer deleteVolume(uuid2)

	select {
	case vol := <-createChan:
		if vol != uuid2 {
			t.Errorf("Excpected uuid = [%s] but obtained uuid = [%s]", uuid2, vol)
		}
	case <-time.After(10 * time.Second):
		t.Fatal("Volume create event not detected")
	}
	controlChan <- true
}
示例#2
0
func TestHealthCheckFilesUpdated(t *testing.T) {
	createChan := make(chan string, 10)
	deleteChan := make(chan string, 10)

	controlChan := make(chan bool, 1)

	//guranteed to be random
	randomUuid := "2b4c73-e432-45f4-96f2-97e0b546e840i"

	tc := &testCattleClient{}

	go func() {
		va := volume.NewVolumeAgent(hc, socketFile, randomUuid, 5, tc, sp)
		err := va.Run(controlChan)
		if err != nil {
			t.Fatalf("Error starting convoy agent err=[%v]", err)
		}
	}()

	go waitForCreateDeleteEvents(tc, createChan, deleteChan, controlChan)
	<-time.After(10 * time.Second)

	fInfo, err := os.Stat(filepath.Join(hc, randomUuid))
	if err != nil {
		t.Fatalf("Error reading healthcheck file err [%v]", err)
	}

	pointOfRef := fInfo.ModTime()

	<-time.After(5 * time.Second)

	fInfo, err = os.Stat(filepath.Join(hc, randomUuid))
	if err != nil {
		t.Fatalf("Error reading healthcheck file err [%v]", err)
	}

	diff := fInfo.ModTime().Unix() - pointOfRef.Unix()
	if diff <= 0 {
		t.Fatalf("healthcheck file has not been updated, oldtime=[%v], newtime=[%v]", pointOfRef, fInfo.ModTime())
	}

	controlChan <- true
}
示例#3
0
func TestCreateEventsOnStartup(t *testing.T) {
	createChan := make(chan string, 10)
	deleteChan := make(chan string, 10)

	controlChan := make(chan bool, 1)

	tc := &testCattleClient{}

	uuid1, err := createVolume("testVol1")
	if err != nil {
		t.Fatalf("Error while creating volume UUID=[%s] err =[%v]", uuid1, err)
	}
	defer deleteVolume(uuid1)
	uuid2, err := createVolume("testVol2")
	if err != nil {
		t.Fatalf("Error while creating volume UUID=[%s] err =[%v]", uuid2, err)
	}
	defer deleteVolume(uuid2)
	uuid3, err := createVolume("testVol3")
	if err != nil {
		t.Fatalf("Error while creating volume UUID=[%s] err =[%v]", uuid2, err)
	}
	defer deleteVolume(uuid3)

	go func() {
		va := volume.NewVolumeAgent(hc, socketFile, h, 5, tc, sp)
		err := va.Run(controlChan)
		if err != nil {
			t.Fatalf("Error starting convoy agent err=[%v]", err)
		}
	}()

	go waitForCreateDeleteEvents(tc, createChan, deleteChan, controlChan)

	obtainedUuids := []string{}

	for i := 0; i < 3; i++ {
		select {
		case vol := <-createChan:
			obtainedUuids = append(obtainedUuids, vol)
		case <-time.After(10 * time.Second):
			t.Fatal("All volume events were not received")
		}
	}

	found1 := true
	found2 := true
	found3 := true

	if len(obtainedUuids) != 3 {
		t.Errorf("created 3 vols but obtained events for %d vols", len(obtainedUuids))
		t.Fail()
	}

	for _, uuid := range obtainedUuids {
		if uuid == uuid1 {
			found1 = true
		}
		if uuid == uuid2 {
			found2 = true
		}
		if uuid == uuid3 {
			found3 = true
		}
	}

	if !found1 || !found2 || !found3 {
		t.Error("obtained Uuids do not match expected Uuids")
	}
	controlChan <- true
}