From 619e980e6d809d2e8a9966a6d88c3e12abfef0da Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Mon, 5 Dec 2016 19:03:33 -0500 Subject: [PATCH] Add integration tests. (#754) --- integration-tests/.dockerignore | 2 + integration-tests/Dockerfile | 11 +++ integration-tests/check-results.rb | 88 +++++++++++++++++++ .../dependent/hourly-dependent-sleep1m.yaml | 10 +++ .../jobs/scheduled/daily-sleep1m.yaml | 9 ++ .../jobs/scheduled/hourly-sleep1m.yaml | 9 ++ .../jobs/scheduled/weekly-sleep1m.yaml | 9 ++ 7 files changed, 138 insertions(+) create mode 100644 integration-tests/.dockerignore create mode 100644 integration-tests/Dockerfile create mode 100755 integration-tests/check-results.rb create mode 100644 integration-tests/jobs/dependent/hourly-dependent-sleep1m.yaml create mode 100644 integration-tests/jobs/scheduled/daily-sleep1m.yaml create mode 100644 integration-tests/jobs/scheduled/hourly-sleep1m.yaml create mode 100644 integration-tests/jobs/scheduled/weekly-sleep1m.yaml diff --git a/integration-tests/.dockerignore b/integration-tests/.dockerignore new file mode 100644 index 000000000..7eaa6632c --- /dev/null +++ b/integration-tests/.dockerignore @@ -0,0 +1,2 @@ +.* +Dockerfile diff --git a/integration-tests/Dockerfile b/integration-tests/Dockerfile new file mode 100644 index 000000000..0bade44bb --- /dev/null +++ b/integration-tests/Dockerfile @@ -0,0 +1,11 @@ +FROM debian:jessie + +RUN apt-get update \ + && apt-get install --no-install-recommends -y --force-yes ruby ruby-dev build-essential \ + && gem install --no-ri --no-rdoc cassandra-driver \ + && apt-get purge -y --auto-remove build-essential \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +ADD https://raw.githubusercontent.com/mesos/chronos/master/bin/chronos-sync.rb /chronos/chronos-sync.rb +COPY . /chronos diff --git a/integration-tests/check-results.rb b/integration-tests/check-results.rb new file mode 100755 index 000000000..6c764c88f --- /dev/null +++ b/integration-tests/check-results.rb @@ -0,0 +1,88 @@ +#!/usr/bin/env ruby + +require 'cassandra' +require 'securerandom' + +CASSANDRA_HOSTS = ['node-0.cassandra.mesos', 'node-1.cassandra.mesos', 'node-2.cassandra.mesos'] +CASSANDRA_PORT = 9042 + +cluster = Cassandra.cluster(hosts: CASSANDRA_HOSTS, port: CASSANDRA_PORT) + +session = cluster.connect + +exit_code = 0 + +future = session.execute_async( + 'SELECT job_name, ts, task_state FROM metrics.chronos WHERE ts >= ? ALLOW FILTERING', + arguments: [(DateTime.now - 7).to_time] +) +result = [] +future.on_success do |rows| + rows.each do |row| + result.push({ + :job_name => row['job_name'], + :ts => row['ts'], + :task_state => row['task_state'], + }) + end +end +future.join + +grouped = result.group_by {|r| r[:job_name]} + +def check_count_equals(count, expected, name, state) + if count != expected + puts "State count for name=#{name} and state=#{state} didn't match expected value (got #{count}, expected #{expected}" + return true + end + false +end + +def check_count_at_least(count, expected, name, state) + if count < expected + puts "State count for name=#{name} and state=#{state} didn't match expected >= value (got #{count}, expected #{expected}" + return true + end + false +end + +def get_expected(name) + if name.include?('hourly') + 24*7 + elsif name.include?('daily') + 7 + elsif name.include?('weekly') + 1 + else + 0 + end +end + +had_error = false +grouped.each do |name, result| + states = result.group_by {|r| r[:task_state]} + counts = states.map{|k, v| {:state => k, :count =>v.size}} + puts "Summary for #{name}:" + puts counts + expected = get_expected(name) + next if expected == 0 + counts.each do |v| + if v[:state] == 'TASK_FINISHED' + if check_count_equals(v[:count], expected, name, v[:state]) + had_error = true + end + elsif v[:state] == 'TASK_RUNNING' + if check_count_at_least(v[:count], expected, name, v[:state]) + had_error = true + end + end + end +end + +if had_error + exit_code = 1 +end + +session.close + +exit exit_code diff --git a/integration-tests/jobs/dependent/hourly-dependent-sleep1m.yaml b/integration-tests/jobs/dependent/hourly-dependent-sleep1m.yaml new file mode 100644 index 000000000..7d058238b --- /dev/null +++ b/integration-tests/jobs/dependent/hourly-dependent-sleep1m.yaml @@ -0,0 +1,10 @@ +--- +name: hourly-dependent-sleep1m +command: sleep 1m +parents: + - hourly-sleep1m +owner: nobody +cpus: 0.01 +mem: 32 +disk: 0 +runAsUser: root diff --git a/integration-tests/jobs/scheduled/daily-sleep1m.yaml b/integration-tests/jobs/scheduled/daily-sleep1m.yaml new file mode 100644 index 000000000..eef88819b --- /dev/null +++ b/integration-tests/jobs/scheduled/daily-sleep1m.yaml @@ -0,0 +1,9 @@ +--- +name: daily-sleep1m +command: sleep 1m +schedule: R/2016-12-05T22:00:00.000Z/P1D +owner: nobody +cpus: 0.01 +mem: 32 +disk: 0 +runAsUser: root diff --git a/integration-tests/jobs/scheduled/hourly-sleep1m.yaml b/integration-tests/jobs/scheduled/hourly-sleep1m.yaml new file mode 100644 index 000000000..8b0b827fa --- /dev/null +++ b/integration-tests/jobs/scheduled/hourly-sleep1m.yaml @@ -0,0 +1,9 @@ +--- +name: hourly-sleep1m +command: sleep 1m +schedule: R/2016-12-05T22:00:00.000Z/PT1H +owner: nobody +cpus: 0.01 +mem: 32 +disk: 0 +runAsUser: root diff --git a/integration-tests/jobs/scheduled/weekly-sleep1m.yaml b/integration-tests/jobs/scheduled/weekly-sleep1m.yaml new file mode 100644 index 000000000..89df08668 --- /dev/null +++ b/integration-tests/jobs/scheduled/weekly-sleep1m.yaml @@ -0,0 +1,9 @@ +--- +name: weekly-sleep1m +command: sleep 1m +schedule: R/2016-12-05T22:00:00.000Z/P1W +owner: nobody +cpus: 0.01 +mem: 32 +disk: 0 +runAsUser: root