Skip to content

Commit 619e980

Browse files
authored
Add integration tests. (#754)
1 parent 2460b3f commit 619e980

File tree

7 files changed

+138
-0
lines changed

7 files changed

+138
-0
lines changed

integration-tests/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.*
2+
Dockerfile

integration-tests/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM debian:jessie
2+
3+
RUN apt-get update \
4+
&& apt-get install --no-install-recommends -y --force-yes ruby ruby-dev build-essential \
5+
&& gem install --no-ri --no-rdoc cassandra-driver \
6+
&& apt-get purge -y --auto-remove build-essential \
7+
&& apt-get clean \
8+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
9+
10+
ADD https://raw.githubusercontent.com/mesos/chronos/master/bin/chronos-sync.rb /chronos/chronos-sync.rb
11+
COPY . /chronos

integration-tests/check-results.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'cassandra'
4+
require 'securerandom'
5+
6+
CASSANDRA_HOSTS = ['node-0.cassandra.mesos', 'node-1.cassandra.mesos', 'node-2.cassandra.mesos']
7+
CASSANDRA_PORT = 9042
8+
9+
cluster = Cassandra.cluster(hosts: CASSANDRA_HOSTS, port: CASSANDRA_PORT)
10+
11+
session = cluster.connect
12+
13+
exit_code = 0
14+
15+
future = session.execute_async(
16+
'SELECT job_name, ts, task_state FROM metrics.chronos WHERE ts >= ? ALLOW FILTERING',
17+
arguments: [(DateTime.now - 7).to_time]
18+
)
19+
result = []
20+
future.on_success do |rows|
21+
rows.each do |row|
22+
result.push({
23+
:job_name => row['job_name'],
24+
:ts => row['ts'],
25+
:task_state => row['task_state'],
26+
})
27+
end
28+
end
29+
future.join
30+
31+
grouped = result.group_by {|r| r[:job_name]}
32+
33+
def check_count_equals(count, expected, name, state)
34+
if count != expected
35+
puts "State count for name=#{name} and state=#{state} didn't match expected value (got #{count}, expected #{expected}"
36+
return true
37+
end
38+
false
39+
end
40+
41+
def check_count_at_least(count, expected, name, state)
42+
if count < expected
43+
puts "State count for name=#{name} and state=#{state} didn't match expected >= value (got #{count}, expected #{expected}"
44+
return true
45+
end
46+
false
47+
end
48+
49+
def get_expected(name)
50+
if name.include?('hourly')
51+
24*7
52+
elsif name.include?('daily')
53+
7
54+
elsif name.include?('weekly')
55+
1
56+
else
57+
0
58+
end
59+
end
60+
61+
had_error = false
62+
grouped.each do |name, result|
63+
states = result.group_by {|r| r[:task_state]}
64+
counts = states.map{|k, v| {:state => k, :count =>v.size}}
65+
puts "Summary for #{name}:"
66+
puts counts
67+
expected = get_expected(name)
68+
next if expected == 0
69+
counts.each do |v|
70+
if v[:state] == 'TASK_FINISHED'
71+
if check_count_equals(v[:count], expected, name, v[:state])
72+
had_error = true
73+
end
74+
elsif v[:state] == 'TASK_RUNNING'
75+
if check_count_at_least(v[:count], expected, name, v[:state])
76+
had_error = true
77+
end
78+
end
79+
end
80+
end
81+
82+
if had_error
83+
exit_code = 1
84+
end
85+
86+
session.close
87+
88+
exit exit_code
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: hourly-dependent-sleep1m
3+
command: sleep 1m
4+
parents:
5+
- hourly-sleep1m
6+
owner: nobody
7+
cpus: 0.01
8+
mem: 32
9+
disk: 0
10+
runAsUser: root
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: daily-sleep1m
3+
command: sleep 1m
4+
schedule: R/2016-12-05T22:00:00.000Z/P1D
5+
owner: nobody
6+
cpus: 0.01
7+
mem: 32
8+
disk: 0
9+
runAsUser: root
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: hourly-sleep1m
3+
command: sleep 1m
4+
schedule: R/2016-12-05T22:00:00.000Z/PT1H
5+
owner: nobody
6+
cpus: 0.01
7+
mem: 32
8+
disk: 0
9+
runAsUser: root
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: weekly-sleep1m
3+
command: sleep 1m
4+
schedule: R/2016-12-05T22:00:00.000Z/P1W
5+
owner: nobody
6+
cpus: 0.01
7+
mem: 32
8+
disk: 0
9+
runAsUser: root

0 commit comments

Comments
 (0)