summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-29 12:13:55 +0300
committerPaul Buetow <paul@buetow.org>2021-10-29 12:13:55 +0300
commita5f0c021f2caecf9adfec65583c915b6c04c27a9 (patch)
treea67df41ebe39f360dd4005a715076aa328f21c9c
parentffa39a17f48ee9847cc85819d8134b5eb9482b77 (diff)
add dserver integration test for scheduled query
-rw-r--r--integrationtests/dserver.cfg20
-rw-r--r--integrationtests/dserver.csv.expected2
-rw-r--r--integrationtests/dserver.csv.query.expected1
-rw-r--r--integrationtests/dserver_test.go53
-rw-r--r--internal/server/continuous.go4
-rw-r--r--internal/server/scheduler.go4
6 files changed, 80 insertions, 4 deletions
diff --git a/integrationtests/dserver.cfg b/integrationtests/dserver.cfg
new file mode 100644
index 0000000..2092b96
--- /dev/null
+++ b/integrationtests/dserver.cfg
@@ -0,0 +1,20 @@
+{
+ "Server": {
+ "Schedule": [
+ {
+ "Name": "dserver_schedule_test",
+ "Enable": true,
+ "AllowFrom": [
+ "localhost"
+ ],
+ "TimeRange": [
+ 0,
+ 24
+ ],
+ "Files": "./mapr_testdata.log",
+ "Query": "from STATS select count($line),last($time),avg($goroutines),min(concurrentConnections),max(lifetimeConnections) group by $hostname",
+ "Outfile": "./dserver.csv"
+ }
+ ]
+ }
+}
diff --git a/integrationtests/dserver.csv.expected b/integrationtests/dserver.csv.expected
new file mode 100644
index 0000000..d4e6f0f
--- /dev/null
+++ b/integrationtests/dserver.csv.expected
@@ -0,0 +1,2 @@
+count($line),last($time),avg($goroutines),min(concurrentconnections),max(lifetimeconnections)
+597,20211002-071949,11.628141,0.000000,6.000000
diff --git a/integrationtests/dserver.csv.query.expected b/integrationtests/dserver.csv.query.expected
new file mode 100644
index 0000000..b45c588
--- /dev/null
+++ b/integrationtests/dserver.csv.query.expected
@@ -0,0 +1 @@
+from STATS select count($line),last($time),avg($goroutines),min(concurrentConnections),max(lifetimeConnections) group by $hostname outfile ./dserver.csv \ No newline at end of file
diff --git a/integrationtests/dserver_test.go b/integrationtests/dserver_test.go
new file mode 100644
index 0000000..0944c79
--- /dev/null
+++ b/integrationtests/dserver_test.go
@@ -0,0 +1,53 @@
+package integrationtests
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "testing"
+
+ "github.com/mimecast/dtail/internal/config"
+)
+
+func TestDServer(t *testing.T) {
+ if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
+ t.Log("Skipping")
+ return
+ }
+
+ csvFile := "dserver.csv"
+ expectedCsvFile := "dserver.csv.expected"
+ queryFile := fmt.Sprintf("%s.query", csvFile)
+ expectedQueryFile := "dserver.csv.query.expected"
+
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ stdoutCh, stderrCh, cmdErrCh, err := startCommand(ctx, t,
+ "../dserver",
+ "--cfg", "dserver.cfg",
+ "--logger", "stdout",
+ "--logLevel", "info",
+ "--bindAddress", "localhost",
+ "--shutdownAfter", "5",
+ "--port", fmt.Sprintf("%d", getUniquePortNumber()),
+ )
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ waitForCommand(ctx, t, stdoutCh, stderrCh, cmdErrCh)
+
+ if err := compareFiles(t, csvFile, expectedCsvFile); err != nil {
+ t.Error(err)
+ return
+ }
+ if err := compareFiles(t, queryFile, expectedQueryFile); err != nil {
+ t.Error(err)
+ return
+ }
+
+ os.Remove(csvFile)
+ os.Remove(queryFile)
+}
diff --git a/internal/server/continuous.go b/internal/server/continuous.go
index 93b3fcb..ac5c686 100644
--- a/internal/server/continuous.go
+++ b/internal/server/continuous.go
@@ -20,8 +20,8 @@ func newContinuous() *continuous {
}
func (c *continuous) start(ctx context.Context) {
- dlog.Server.Info("Starting continuous job runner after 10s")
- time.Sleep(time.Second * 10)
+ dlog.Server.Info("Starting continuous job runner after 2s")
+ time.Sleep(time.Second * 2)
c.runJobs(ctx)
}
diff --git a/internal/server/scheduler.go b/internal/server/scheduler.go
index 0ba65f7..36f167d 100644
--- a/internal/server/scheduler.go
+++ b/internal/server/scheduler.go
@@ -23,9 +23,9 @@ func newScheduler() *scheduler {
}
func (s *scheduler) start(ctx context.Context) {
- dlog.Server.Info("Starting scheduled job runner after 10s")
+ dlog.Server.Info("Starting scheduled job runner after 2s")
// First run after just 10s!
- time.Sleep(time.Second * 10)
+ time.Sleep(time.Second * 2)
s.runJobs(ctx)
for {
select {