Пример #1
0
func getOneWork(t *testing.T, j *jobserver.JobServer) (ok bool, workSpecName, workUnitKey string, workUnitData map[string]interface{}) {
	anything, msg, err := j.GetWork("test", map[string]interface{}{"available_gb": 1})
	if !assert.NoError(t, err) {
		return
	}
	assert.Empty(t, msg)
	// Since we didn't request multiple work units we should always
	// get at most one, but maybe none
	if assert.NotNil(t, anything) &&
		assert.IsType(t, cborrpc.PythonTuple{}, anything) {
		tuple := anything.(cborrpc.PythonTuple)
		if assert.Len(t, tuple.Items, 3) {
			// "no work unit" gets returned as tuple (nil,
			// nil, nil)
			if tuple.Items[0] != nil &&
				assert.IsType(t, "", tuple.Items[0]) &&
				assert.IsType(t, []byte{}, tuple.Items[1]) &&
				assert.IsType(t, map[string]interface{}{}, tuple.Items[2]) {
				ok = true
				workSpecName = tuple.Items[0].(string)
				bWorkUnitKey := tuple.Items[1].([]byte)
				workUnitKey = string(bWorkUnitKey)
				workUnitData = tuple.Items[2].(map[string]interface{})
			}
		}
	}
	return
}
Пример #2
0
// getSpecificWork calls GetWork expecting a specific work unit to
// come back, and returns its data dictionary.
func getSpecificWork(t *testing.T, j *jobserver.JobServer, workSpecName, workUnitKey string) map[string]interface{} {
	anything, msg, err := j.GetWork("test", map[string]interface{}{"available_gb": 1})
	if !assert.NoError(t, err) {
		return nil
	}
	assert.Empty(t, msg)
	if assert.NotNil(t, anything) && assert.IsType(t, cborrpc.PythonTuple{}, anything) {
		tuple := anything.(cborrpc.PythonTuple)
		if assert.Len(t, tuple.Items, 3) && assert.NotNil(t, tuple.Items[0]) {
			assert.Equal(t, workSpecName, tuple.Items[0])
			assert.Equal(t, []byte(workUnitKey), tuple.Items[1])
			if assert.IsType(t, tuple.Items[2], map[string]interface{}{}) {
				return tuple.Items[2].(map[string]interface{})
			}
		}
	}
	return nil
}