Skip to content

Commit

Permalink
Add integration tests. (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
brndnmtthws committed Dec 6, 2016
1 parent 2460b3f commit 619e980
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 0 deletions.
2 changes: 2 additions & 0 deletions integration-tests/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.*
Dockerfile
11 changes: 11 additions & 0 deletions integration-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
88 changes: 88 additions & 0 deletions integration-tests/check-results.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions integration-tests/jobs/dependent/hourly-dependent-sleep1m.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions integration-tests/jobs/scheduled/daily-sleep1m.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions integration-tests/jobs/scheduled/hourly-sleep1m.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions integration-tests/jobs/scheduled/weekly-sleep1m.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 619e980

Please sign in to comment.