Exemple #1
0
func TestCheckCoresAvailable(t *testing.T) {
	defer freeCores()

	req := 2
	req_wrong := c_NCORES + 1
	id := "pippo"
	assert.True(t, CheckCoresAvailable(req))
	assert.False(t, CheckCoresAvailable(req_wrong))

	assignCores(3, id)
	assert.False(t, CheckCoresAvailable(req))
}
Exemple #2
0
func TestCheckSpecificCoresAvailable(t *testing.T) {
	defer freeCores()

	req := "0,3"
	req_tooMany := "0,1,2,3,4,5"
	req_wrongNumber := "0,1,85"
	id := "pippo"
	assert.True(t, CheckSpecificCoresAvailable(req))
	assert.False(t, CheckSpecificCoresAvailable(req_tooMany))
	assert.False(t, CheckSpecificCoresAvailable(req_wrongNumber))

	assignCores(3, id)
	assert.False(t, CheckSpecificCoresAvailable(req))
}
Exemple #3
0
func TestGetCoresAvailable(t *testing.T) {
	defer freeCores()

	var assigned string
	var ok bool

	req := 2
	id := "pippo"
	assigned, ok = GetCoresAvailable(req)
	assert.True(t, ok)
	assert.Equal(t, "0,1", assigned)

	freeCores()
	assignSpecificCores([]int{1, 3}, id)
	assigned, ok = GetCoresAvailable(req)
	assert.True(t, ok)
	assert.Equal(t, "0,2", assigned)

	freeCores()
	req_wrong := c_NCORES + 1
	assigned, ok = GetCoresAvailable(req_wrong)
	assert.False(t, ok)
	assert.Equal(t, "", assigned)

}
Exemple #4
0
func TestContainsString(t *testing.T) {
	values := []string{"a", "b", "c"}
	valueTrue := "a"
	valueFalse := "d"

	assert.True(t, ContainsString(values, valueTrue))
	assert.False(t, ContainsString(values, valueFalse))
}
Exemple #5
0
func TestIsFull(t *testing.T) {
	b := BuildBuffer(5)
	values := []float64{1, 2, 3, 4, 5}
	var f bool

	f = b.isFull()
	assert.False(t, f)

	b.values = append(b.values, values...)
	f = b.isFull()
	assert.True(t, f)
}
Exemple #6
0
func TestIsReadyForRunning(t *testing.T) {
	id := "id1"
	defer delete(instancesMetrics, id)

	instancesMetrics[id] = Metric{
		BaseMetrics: make(map[string][]float64),
	}

	values1 := []float64{1, 2}
	values2 := []float64{1, 2, 3, 4}
	values3 := []float64{1, 2, 3, 4, 5}
	instancesMetrics[id].BaseMetrics[enum.METRIC_CPU_INST.ToString()] = values1
	instancesMetrics[id].BaseMetrics[enum.METRIC_CPU_SYS.ToString()] = values2
	instancesMetrics[id].BaseMetrics[enum.METRIC_MEM_INST.ToString()] = values3
	thr1 := len(values1)
	thr2 := len(values2)
	thr3 := len(values3)

	assert.True(t, IsReadyForRunning(id, thr1))
	assert.False(t, IsReadyForRunning(id, thr2))
	assert.False(t, IsReadyForRunning(id, thr3))
}