예제 #1
0
func (s *WorkerTestSuite) TestWorkerSlow001NoExamples(t *C) {
	job := &qan.Job{
		Id:             "99",
		SlowLogFile:    testlog.Sample + "slow001.log",
		StartOffset:    0,
		EndOffset:      524,
		RunTime:        time.Duration(3 * time.Second),
		ZeroRunTime:    true,
		ExampleQueries: false,
	}
	w := qan.NewSlowLogWorker(s.logger, "qan-worker-1")
	got, _ := w.Run(job)

	expect := &qan.Result{}
	if err := test.LoadMmReport(sample+"slow001-no-examples.json", expect); err != nil {
		t.Fatal(err)
	}

	if same, diff := test.IsDeeply(got, expect); !same {
		test.Dump(got)
		t.Error(diff)
	}

	// Worker should be able to report its name and status.
	t.Check(w.Name(), Equals, "qan-worker-1")
	t.Check(w.Status(), Equals, "Done job "+job.Id)
}
예제 #2
0
func (s *WorkerTestSuite) TestResult014(t *C) {
	job := &qan.Job{
		SlowLogFile:    testlog.Sample + "slow014.log",
		StartOffset:    0,
		EndOffset:      127118681,
		RunTime:        time.Duration(3 * time.Second),
		ZeroRunTime:    true,
		ExampleQueries: true,
	}
	w := qan.NewSlowLogWorker(s.logger, "qan-worker-1")
	result, _ := w.Run(job)

	start := time.Now().Add(-1 * time.Second)
	stop := time.Now()
	it := proto.ServiceInstance{Service: "mysql", InstanceId: 1}
	interval := &qan.Interval{
		Filename:    "slow.log",
		StartTime:   start,
		StopTime:    stop,
		StartOffset: 0,
		EndOffset:   127118680,
	}
	config := qan.Config{
		ReportLimit: 500,
	}
	report := qan.MakeReport(it, interval, result, config)

	t.Check(report.Global.TotalQueries, Equals, uint64(4))
	t.Check(report.Global.UniqueQueries, Equals, uint64(4))
	t.Assert(report.Class, HasLen, 4)
	// This query required improving the log parser to get the correct checksum ID:
	t.Check(report.Class[0].Id, Equals, "DB9EF18846547B8C")
}
예제 #3
0
func (s *WorkerTestSuite) RunWorker(job *qan.Job) string {
	w := qan.NewSlowLogWorker(s.logger, "qan-worker-1")
	result, _ := w.Run(job)

	// Write the result as formatted JSON to a file...
	tmpFilename := fmt.Sprintf("/tmp/pct-test.%d", os.Getpid())
	test.WriteData(result, tmpFilename)
	return tmpFilename
}
예제 #4
0
func (s *WorkerTestSuite) TestWorkerSlow011(t *C) {
	// Percona Server rate limit
	job := &qan.Job{
		SlowLogFile:    testlog.Sample + "slow011.log",
		StartOffset:    0,
		EndOffset:      3000,
		RunTime:        time.Duration(3 * time.Second),
		ZeroRunTime:    true,
		ExampleQueries: true,
	}
	w := qan.NewSlowLogWorker(s.logger, "qan-worker-1")
	got, _ := w.Run(job)

	expect := &qan.Result{}
	if err := test.LoadMmReport(sample+"slow011.json", expect); err != nil {
		t.Fatal(err)
	}

	if same, diff := test.IsDeeply(got, expect); !same {
		test.Dump(got)
		t.Error(diff)
	}
}