func (s *WorkerTestSuite) TestWorkerSlow001Half(t *C) { // This tests that the worker will stop processing events before // the end of the slow log file. 358 is the last byte of the first // (of 2) events. i := &qan.Interval{ Number: 1, StartTime: s.now, StopTime: s.now.Add(1 * time.Minute), Filename: inputDir + "slow001.log", StartOffset: 0, EndOffset: 358, } got, err := s.RunWorker(s.config, mock.NewNullMySQL(), i) t.Check(err, IsNil) expect := &qan.Result{} if err := test.LoadMmReport(outputDir+"slow001-half.json", expect); err != nil { t.Fatal(err) } sort.Sort(ByQueryId(got.Class)) sort.Sort(ByQueryId(expect.Class)) if ok, diff := IsDeeply(got, expect); !ok { Dump(got) t.Error(diff) } }
func (s *WorkerTestSuite) TestWorkerSlow001(t *C) { i := &qan.Interval{ Number: 1, StartTime: s.now, StopTime: s.now.Add(1 * time.Minute), Filename: inputDir + "slow001.log", StartOffset: 0, EndOffset: 524, } got, err := s.RunWorker(s.config, mock.NewNullMySQL(), i) t.Check(err, IsNil) expect := &qan.Result{} test.LoadMmReport(outputDir+"slow001.json", expect) sort.Sort(ByQueryId(got.Class)) sort.Sort(ByQueryId(expect.Class)) if ok, diff := IsDeeply(got, expect); !ok { Dump(got) t.Error(diff) } }
func (s *WorkerTestSuite) TestWorkerWithAnotherTZ(t *C) { if s.dsn == "" { t.Fatal("PCT_TEST_MYSQL_DSN is not set") } mysqlConn := mysql.NewConnection(s.dsn) err := mysqlConn.Connect(1) t.Assert(err, IsNil) defer mysqlConn.Close() mysqlConn.DB().Exec(`SET @@global.time_zone="-1:00"`) mysqlConn.DB().Exec(`SET time_zone="-1:00"`) // Reset the timezone or other tests could fail mysqlConn.DB().Exec(`SET @@global.time_zone="+00:00"`) defer mysqlConn.DB().Exec(`SET time_zone="+00:00"`) i := &qan.Interval{ Number: 1, StartTime: s.now, StopTime: s.now.Add(1 * time.Minute), Filename: inputDir + "slow001.log", StartOffset: 0, EndOffset: 524, } got, err := s.RunWorker(s.config, mysqlConn, i) t.Check(err, IsNil) expect := &qan.Result{} test.LoadMmReport(outputDir+"slow001.json", expect) // I'm going to use the same results for TestWorkerSlow001 // But simulating tz = UTC -1 expect.Class[0].Example.Ts = "2007-10-15 22:45:10" expect.Class[1].Example.Ts = "2007-10-15 22:43:52" sort.Sort(ByQueryId(got.Class)) sort.Sort(ByQueryId(expect.Class)) if ok, diff := IsDeeply(got, expect); !ok { Dump(got) t.Error(diff) } }
func (s *WorkerTestSuite) TestWorkerSlow011(t *C) { // Percona Server rate limit i := &qan.Interval{ Number: 1, StartTime: s.now, StopTime: s.now.Add(1 * time.Minute), Filename: inputDir + "slow011.log", StartOffset: 0, EndOffset: 3000, } got, err := s.RunWorker(s.config, mock.NewNullMySQL(), i) t.Check(err, IsNil) expect := &qan.Result{} if err := test.LoadMmReport(outputDir+"slow011.json", expect); err != nil { t.Fatal(err) } sort.Sort(ByQueryId(got.Class)) sort.Sort(ByQueryId(expect.Class)) if same, diff := IsDeeply(got, expect); !same { Dump(got) t.Error(diff) } }
func (s *WorkerTestSuite) TestWorkerSlow001Resume(t *C) { // This tests that the worker will resume processing events from // somewhere in the slow log file. 359 is the first byte of the // second (of 2) events. i := &qan.Interval{ Number: 2, StartTime: s.now, StopTime: s.now.Add(1 * time.Minute), Filename: inputDir + "slow001.log", StartOffset: 359, EndOffset: 524, } got, err := s.RunWorker(s.config, mock.NewNullMySQL(), i) t.Check(err, IsNil) expect := &qan.Result{} test.LoadMmReport(outputDir+"slow001-resume.json", expect) sort.Sort(ByQueryId(got.Class)) sort.Sort(ByQueryId(expect.Class)) if ok, diff := IsDeeply(got, expect); !ok { Dump(got) t.Error(diff) } }
func (s *WorkerTestSuite) TestWorkerSlow001NoExamples(t *C) { i := &qan.Interval{ Number: 99, StartTime: s.now, StopTime: s.now.Add(1 * time.Minute), Filename: inputDir + "slow001.log", StartOffset: 0, EndOffset: 524, } config := s.config config.ExampleQueries = false got, err := s.RunWorker(config, mock.NewNullMySQL(), i) t.Check(err, IsNil) expect := &qan.Result{} if err := test.LoadMmReport(outputDir+"slow001-no-examples.json", expect); err != nil { t.Fatal(err) } sort.Sort(ByQueryId(got.Class)) sort.Sort(ByQueryId(expect.Class)) if same, diff := IsDeeply(got, expect); !same { Dump(got) t.Error(diff) } }