当前位置: 首页>>代码示例>>Golang>>正文


Golang exec.SetRunForTesting函数代码示例

本文整理汇总了Golang中go/skia/org/infra/go/exec.SetRunForTesting函数的典型用法代码示例。如果您正苦于以下问题:Golang SetRunForTesting函数的具体用法?Golang SetRunForTesting怎么用?Golang SetRunForTesting使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SetRunForTesting函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestChromiumPerfExecute

func TestChromiumPerfExecute(t *testing.T) {
	task := pendingChromiumPerfTask()
	mockRun := exec.CommandCollector{}
	exec.SetRunForTesting(mockRun.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	mockRun.SetDelegateRun(func(cmd *exec.Command) error {
		runId := getRunId(t, cmd)
		assertFileContents(t, filepath.Join(os.TempDir(), runId+".chromium.patch"),
			"chromiumpatch\n")
		assertFileContents(t, filepath.Join(os.TempDir(), runId+".skia.patch"),
			"skiapatch\n")
		return nil
	})
	err := task.Execute()
	assert.NoError(t, err)
	assert.Len(t, mockRun.Commands(), 1)
	cmd := mockRun.Commands()[0]
	expect.Equal(t, "run_chromium_perf_on_workers", cmd.Name)
	expect.Contains(t, cmd.Args, "--gae_task_id=42")
	expect.Contains(t, cmd.Args, "--description=description")
	expect.Contains(t, cmd.Args, "[email protected]")
	expect.Contains(t, cmd.Args, "--benchmark_name=benchmark")
	expect.Contains(t, cmd.Args, "--target_platform=Linux")
	expect.Contains(t, cmd.Args, "--pageset_type=All")
	expect.Contains(t, cmd.Args, "--repeat_benchmark=1")
	expect.Contains(t, cmd.Args, "--benchmark_extra_args=benchmarkargs")
	expect.Contains(t, cmd.Args, "--browser_extra_args_nopatch=banp")
	expect.Contains(t, cmd.Args, "--browser_extra_args_withpatch=bawp")
	runId := getRunId(t, cmd)
	expect.Contains(t, cmd.Args, "--log_id="+runId)
	expect.NotNil(t, cmd.Timeout)
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:32,代码来源:poller_test.go

示例2: TestPollAndExecOnceError

func TestPollAndExecOnceError(t *testing.T) {
	task := pendingRecreateWebpageArchivesTask()
	mockServer := frontend.MockServer{}
	mockServer.SetCurrentTask(&task.RecreateWebpageArchivesDBTask)
	defer frontend.CloseTestServer(frontend.InitTestServer(&mockServer))
	commandCollector := exec.CommandCollector{}
	mockRun := exec.MockRun{}
	commandCollector.SetDelegateRun(mockRun.Run)
	exec.SetRunForTesting(commandCollector.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	mockRun.AddRule("capture_archives_on_workers", fmt.Errorf("workers too lazy"))
	pollAndExecOnce()
	// Expect only one poll.
	expect.Equal(t, 1, mockServer.OldestPendingTaskReqCount())
	// Expect three commands: git pull; make all; capture_archives_on_workers ...
	commands := commandCollector.Commands()
	assert.Len(t, commands, 3)
	expect.Equal(t, "git pull", exec.DebugString(commands[0]))
	expect.Equal(t, "make all", exec.DebugString(commands[1]))
	expect.Equal(t, "capture_archives_on_workers", commands[2].Name)
	// Expect an update marking task failed when command fails to execute.
	assert.Len(t, mockServer.UpdateTaskReqs(), 1)
	updateReq := mockServer.UpdateTaskReqs()[0]
	assert.Equal(t, "/"+ctfeutil.UPDATE_RECREATE_WEBPAGE_ARCHIVES_TASK_POST_URI, updateReq.Url)
	assert.NoError(t, updateReq.Error)
	assert.False(t, updateReq.Vars.TsStarted.Valid)
	assert.True(t, updateReq.Vars.TsCompleted.Valid)
	assert.True(t, updateReq.Vars.Failure.Valid)
	assert.True(t, updateReq.Vars.Failure.Bool)
	assert.False(t, updateReq.Vars.RepeatAfterDays.Valid)
	assert.Equal(t, int64(42), updateReq.Vars.Id)
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:32,代码来源:poller_test.go

示例3: TestLuaScriptExecuteWithAggregator

func TestLuaScriptExecuteWithAggregator(t *testing.T) {
	task := pendingLuaScriptTaskWithAggregator()
	mockRun := exec.CommandCollector{}
	exec.SetRunForTesting(mockRun.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	mockRun.SetDelegateRun(func(cmd *exec.Command) error {
		runId := getRunId(t, cmd)
		assertFileContents(t, filepath.Join(os.TempDir(), runId+".lua"),
			`print("lualualua")`)
		assertFileContents(t, filepath.Join(os.TempDir(), runId+".aggregator"),
			`print("aaallluuu")`)
		return nil
	})
	err := task.Execute()
	assert.NoError(t, err)
	assert.Len(t, mockRun.Commands(), 1)
	cmd := mockRun.Commands()[0]
	expect.Equal(t, "run_lua_on_workers", cmd.Name)
	expect.Contains(t, cmd.Args, "--gae_task_id=42")
	expect.Contains(t, cmd.Args, "--description=description")
	expect.Contains(t, cmd.Args, "[email protected]")
	expect.Contains(t, cmd.Args, "--pageset_type=All")
	expect.Contains(t, cmd.Args, "--chromium_build=c14d891-586101c")
	runId := getRunId(t, cmd)
	expect.Contains(t, cmd.Args, "--log_id="+runId)
	expect.NotNil(t, cmd.Timeout)
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:27,代码来源:poller_test.go

示例4: TestPollAndExecOnceMultipleTasks

func TestPollAndExecOnceMultipleTasks(t *testing.T) {
	task1 := pendingRecreateWebpageArchivesTask()
	mockServer := frontend.MockServer{}
	mockServer.SetCurrentTask(&task1.RecreateWebpageArchivesDBTask)
	defer frontend.CloseTestServer(frontend.InitTestServer(&mockServer))
	mockExec := exec.CommandCollector{}
	exec.SetRunForTesting(mockExec.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	// Poll frontend and execute the first task.
	pollAndExecOnce()
	// Update current task.
	task2 := pendingChromiumPerfTask()
	mockServer.SetCurrentTask(&task2.DBTask)
	// Poll frontend and execute the second task.
	pollAndExecOnce()

	// Expect two pending task requests.
	expect.Equal(t, 2, mockServer.OldestPendingTaskReqCount())
	// Expect six commands: git pull; make all; capture_archives_on_workers ...; git pull;
	// make all; run_chromium_perf_on_workers ...
	commands := mockExec.Commands()
	assert.Len(t, commands, 6)
	expect.Equal(t, "git pull", exec.DebugString(commands[0]))
	expect.Equal(t, "make all", exec.DebugString(commands[1]))
	expect.Equal(t, "capture_archives_on_workers", commands[2].Name)
	expect.Equal(t, "git pull", exec.DebugString(commands[3]))
	expect.Equal(t, "make all", exec.DebugString(commands[4]))
	expect.Equal(t, "run_chromium_perf_on_workers", commands[5].Name)
	// No updates expected when commands succeed.
	expect.Empty(t, mockServer.UpdateTaskReqs())
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:31,代码来源:poller_test.go

示例5: TestDoWorkerHealthCheck

func TestDoWorkerHealthCheck(t *testing.T) {
	mockExec := exec.CommandCollector{}
	exec.SetRunForTesting(mockExec.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	doWorkerHealthCheck()
	// Expect three commands: git pull; make all; check_workers_health --log_dir=/b/storage/glog
	commands := mockExec.Commands()
	assert.Len(t, commands, 3)
	expect.Equal(t, "git pull", exec.DebugString(commands[0]))
	expect.Equal(t, "make all", exec.DebugString(commands[1]))
	expect.Equal(t, "check_workers_health --log_dir=/b/storage/glog --local=false",
		exec.DebugString(commands[2]))
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:13,代码来源:poller_test.go

示例6: main

func main() {
	defer common.LogPanic()
	common.Init()

	if logDirFlag := flag.Lookup("log_dir"); logDirFlag != nil {
		logDir = logDirFlag.Value.String()
	}

	if *dryRun {
		exec.SetRunForTesting(func(command *exec.Command) error {
			glog.Infof("dry_run: %s", exec.DebugString(command))
			return nil
		})
	}
	if *local {
		frontend.InitForTesting("http://localhost:8000/")
	} else {
		frontend.MustInit()
	}

	workerHealthTick := time.Tick(*workerHealthCheckInterval)
	pollTick := time.Tick(*pollInterval)
	// Run immediately, since pollTick will not fire until after pollInterval.
	pollAndExecOnce()
	for {
		select {
		case <-workerHealthTick:
			doWorkerHealthCheck()
		case <-pollTick:
			pollAndExecOnce()
		}
	}
}
开发者ID:Tiger66639,项目名称:skia-buildbot,代码行数:33,代码来源:main.go

示例7: main

func main() {
	defer common.LogPanic()
	master_common.InitWithMetrics("ct-poller", graphiteServer)

	if logDirFlag := flag.Lookup("log_dir"); logDirFlag != nil {
		logDir = logDirFlag.Value.String()
	}

	if *dryRun {
		exec.SetRunForTesting(func(command *exec.Command) error {
			glog.Infof("dry_run: %s", exec.DebugString(command))
			return nil
		})
	}

	statusTracker.(*heartbeatStatusTracker).StartMetrics()

	workerHealthTick := time.Tick(*workerHealthCheckInterval)
	pollTick := time.Tick(*pollInterval)
	// Run immediately, since pollTick will not fire until after pollInterval.
	pollAndExecOnce()
	for {
		select {
		case <-workerHealthTick:
			doWorkerHealthCheck()
		case <-pollTick:
			pollAndExecOnce()
		}
	}
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:30,代码来源:main.go

示例8: TestDoWorkerHealthCheckError

// Test that an error executing check_workers_health does not bubble up.
func TestDoWorkerHealthCheckError(t *testing.T) {
	commandCollector := exec.CommandCollector{}
	mockRun := exec.MockRun{}
	commandCollector.SetDelegateRun(mockRun.Run)
	exec.SetRunForTesting(commandCollector.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	mockRun.AddRule("check_workers_health", fmt.Errorf("I'm not a doctor."))
	// Expect error to be logged and ignored.
	doWorkerHealthCheck()
	// Expect three commands: git pull; make all; check_workers_health --log_dir=/b/storage/glog
	commands := commandCollector.Commands()
	assert.Len(t, commands, 3)
	expect.Equal(t, "git pull", exec.DebugString(commands[0]))
	expect.Equal(t, "make all", exec.DebugString(commands[1]))
	expect.Equal(t, "check_workers_health --log_dir=/b/storage/glog --local=false",
		exec.DebugString(commands[2]))
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:18,代码来源:poller_test.go

示例9: TestRecreatePageSetsExecute

func TestRecreatePageSetsExecute(t *testing.T) {
	task := pendingRecreatePageSetsTask()
	mockRun := exec.CommandCollector{}
	exec.SetRunForTesting(mockRun.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	err := task.Execute()
	assert.NoError(t, err)
	assert.Len(t, mockRun.Commands(), 1)
	cmd := mockRun.Commands()[0]
	expect.Equal(t, "create_pagesets_on_workers", cmd.Name)
	expect.Contains(t, cmd.Args, "--gae_task_id=42")
	expect.Contains(t, cmd.Args, "[email protected]")
	expect.Contains(t, cmd.Args, "--pageset_type=All")
	runId := getRunId(t, cmd)
	expect.Contains(t, cmd.Args, "--log_id="+runId)
	expect.NotNil(t, cmd.Timeout)
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:17,代码来源:poller_test.go

示例10: TestPollAndExecOnceNoTasks

func TestPollAndExecOnceNoTasks(t *testing.T) {
	mockServer := frontend.MockServer{}
	mockServer.SetCurrentTask(nil)
	defer frontend.CloseTestServer(frontend.InitTestServer(&mockServer))
	mockExec := exec.CommandCollector{}
	exec.SetRunForTesting(mockExec.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	// Poll frontend, no tasks.
	pollAndExecOnce()
	pollAndExecOnce()
	pollAndExecOnce()
	// Expect three polls.
	expect.Equal(t, 3, mockServer.OldestPendingTaskReqCount())
	// Expect no commands.
	expect.Empty(t, mockExec.Commands())
	// No updates expected.
	expect.Empty(t, mockServer.UpdateTaskReqs())
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:18,代码来源:poller_test.go

示例11: TestCaptureSkpsExecute

func TestCaptureSkpsExecute(t *testing.T) {
	task := pendingCaptureSkpsTask()
	mockRun := exec.CommandCollector{}
	exec.SetRunForTesting(mockRun.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	err := task.Execute()
	assert.NoError(t, err)
	assert.Len(t, mockRun.Commands(), 1)
	cmd := mockRun.Commands()[0]
	expect.Equal(t, "capture_skps_on_workers", cmd.Name)
	expect.Contains(t, cmd.Args, "--gae_task_id=42")
	expect.Contains(t, cmd.Args, "--description=description")
	expect.Contains(t, cmd.Args, "[email protected]")
	expect.Contains(t, cmd.Args, "--pageset_type=All")
	expect.Contains(t, cmd.Args, "--chromium_build=c14d891-586101c")
	runId := getRunId(t, cmd)
	expect.Contains(t, cmd.Args, "--log_id="+runId)
	expect.NotNil(t, cmd.Timeout)
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:19,代码来源:poller_test.go

示例12: TestChromiumBuildExecute

func TestChromiumBuildExecute(t *testing.T) {
	task := pendingChromiumBuildTask()
	mockRun := exec.CommandCollector{}
	exec.SetRunForTesting(mockRun.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	err := task.Execute()
	assert.NoError(t, err)
	assert.Len(t, mockRun.Commands(), 1)
	cmd := mockRun.Commands()[0]
	expect.Equal(t, "build_chromium", cmd.Name)
	expect.Contains(t, cmd.Args, "--gae_task_id=42")
	expect.Contains(t, cmd.Args, "[email protected]")
	expect.Contains(t, cmd.Args,
		"--chromium_hash=c14d891d44f0afff64e56ed7c9702df1d807b1ee")
	expect.Contains(t, cmd.Args,
		"--skia_hash=586101c79b0490b50623e76c71a5fd67d8d92b08")
	runId := getRunId(t, cmd)
	expect.Contains(t, cmd.Args, "--log_id="+runId)
	expect.NotNil(t, cmd.Timeout)
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:20,代码来源:poller_test.go

示例13: TestPollAndExecOnce

func TestPollAndExecOnce(t *testing.T) {
	task := pendingRecreateWebpageArchivesTask()
	mockServer := frontend.MockServer{}
	mockServer.SetCurrentTask(&task.RecreateWebpageArchivesDBTask)
	defer frontend.CloseTestServer(frontend.InitTestServer(&mockServer))
	mockExec := exec.CommandCollector{}
	exec.SetRunForTesting(mockExec.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	pollAndExecOnce()
	// Expect only one poll.
	expect.Equal(t, 1, mockServer.OldestPendingTaskReqCount())
	// Expect three commands: git pull; make all; capture_archives_on_workers ...
	commands := mockExec.Commands()
	assert.Len(t, commands, 3)
	expect.Equal(t, "git pull", exec.DebugString(commands[0]))
	expect.Equal(t, "make all", exec.DebugString(commands[1]))
	expect.Equal(t, "capture_archives_on_workers", commands[2].Name)
	// No updates expected. (capture_archives_on_workers would send updates if it were
	// executed.)
	expect.Empty(t, mockServer.UpdateTaskReqs())
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:21,代码来源:poller_test.go

示例14: TestLuaScriptExecuteWithoutAggregator

func TestLuaScriptExecuteWithoutAggregator(t *testing.T) {
	task := LuaScriptTask{
		DBTask: lua_scripts.DBTask{
			CommonCols:          pendingCommonCols(),
			PageSets:            "All",
			ChromiumRev:         "c14d891d44f0afff64e56ed7c9702df1d807b1ee",
			SkiaRev:             "586101c79b0490b50623e76c71a5fd67d8d92b08",
			LuaScript:           `print("lualualua")`,
			LuaAggregatorScript: "",
			Description:         "description",
		},
	}
	mockRun := exec.CommandCollector{}
	exec.SetRunForTesting(mockRun.Run)
	defer exec.SetRunForTesting(exec.DefaultRun)
	mockRun.SetDelegateRun(func(cmd *exec.Command) error {
		runId := getRunId(t, cmd)
		assertFileContents(t, filepath.Join(os.TempDir(), runId+".lua"),
			`print("lualualua")`)
		_, err := os.Stat(filepath.Join(os.TempDir(), runId+".aggregator"))
		expect.True(t, os.IsNotExist(err))
		return nil
	})
	err := task.Execute()
	assert.NoError(t, err)
	assert.Len(t, mockRun.Commands(), 1)
	cmd := mockRun.Commands()[0]
	expect.Equal(t, "run_lua_on_workers", cmd.Name)
	expect.Contains(t, cmd.Args, "--gae_task_id=42")
	expect.Contains(t, cmd.Args, "[email protected]")
	expect.Contains(t, cmd.Args, "--pageset_type=All")
	expect.Contains(t, cmd.Args, "--chromium_build=c14d891-586101c")
	runId := getRunId(t, cmd)
	expect.Contains(t, cmd.Args, "--log_id="+runId)
	expect.NotNil(t, cmd.Timeout)
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:36,代码来源:poller_test.go


注:本文中的go/skia/org/infra/go/exec.SetRunForTesting函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。