2 Copyright 2014 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
7 <link rel="import" href="../ct-failure-group.html">
12 var assert = chai.assert;
14 describe('ct-sheriff-failure-group', function() {
16 beforeEach(function() {
17 localStorage.removeItem('CTFailureGroupAnnotations');
21 function newFailureWithAnnotation(annotation, isTreeCloser) {
22 return new CTStepFailure('step', 'reason', [
23 {key: String(key++), annotation: annotation, isTreeCloser: isTreeCloser}
27 describe('category', function() {
28 it('should be "default" by default', function() {
29 var group = new CTFailureGroup('', new CTStepFailureGroupData([]));
30 assert.equal(group.category, 'default');
33 it('should be "snoozed" when snoozed', function() {
34 var group = new CTFailureGroup('', new CTStepFailureGroupData(
35 [newFailureWithAnnotation({snoozeTime: Date.now() + 1000 * 1000})]));
36 assert.equal(group.category, 'snoozed');
39 it('should be "failedOnce" when there is only one failure', function() {
40 var failure = newFailureWithAnnotation();
41 failure.resultNodesByBuilder = {some_key: {failingBuildCount: 1}}
42 var group = new CTFailureGroup('', new CTStepFailureGroupData(
44 assert.equal(group.category, 'failedOnce');
47 it('should be "failedOnce" when each failure only failed once', function() {
48 var failure = newFailureWithAnnotation();
49 failure.resultNodesByBuilder = {some_key: {failingBuildCount: 1}}
50 var failure2 = newFailureWithAnnotation();
51 failure2.resultNodesByBuilder = {some_key: {failingBuildCount: 1}}
52 var group = new CTFailureGroup('', new CTStepFailureGroupData(
53 [failure, failure2]));
54 assert.equal(group.category, 'failedOnce');
57 it('should not be "failedOnce" when there is more than one failure', function() {
58 var failure = newFailureWithAnnotation();
59 failure.resultNodesByBuilder = {some_key: {failingBuildCount: 1},
60 other_key: {failingBuildCount: 1}}
61 var group = new CTFailureGroup('', new CTStepFailureGroupData(
63 assert.equal(group.category, 'default');
66 it('treeCloser should win over failedOnce', function() {
67 var failure = newFailureWithAnnotation();
68 failure.resultNodesByBuilder = {some_key: {failingBuildCount: 1, isTreeCloser: true}}
69 var group = new CTFailureGroup('', new CTStepFailureGroupData(
71 assert.equal(group.category, 'treeCloser');
74 it('snoozed should win over treeCloser', function() {
75 var failure = newFailureWithAnnotation({snoozeTime: Date.now() + 1000 * 1000}, true);
76 var group = new CTFailureGroup('', new CTStepFailureGroupData(
78 assert.equal(group.category, 'snoozed');
82 describe('snooze', function() {
83 it('should set isSnoozed', function(done) {
84 var group = new CTFailureGroup('', new CTStepFailureGroupData([newFailureWithAnnotation()]));
85 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() {
86 assert.isTrue(group.isSnoozed);
92 describe('unsnooze', function() {
93 it('should clear isSnoozed', function(done) {
94 var group = new CTFailureGroup('', new CTStepFailureGroupData([newFailureWithAnnotation()]));
95 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() {
96 group.unsnooze().then(function() {
97 assert.isFalse(group.isSnoozed);
104 describe('setBug', function() {
105 it('should store the bug', function(done) {
106 var group = new CTFailureGroup('', new CTStepFailureGroupData([newFailureWithAnnotation()]));
107 group.setBug('123').then(function() {
108 assert.equal(group.bug, 'https://crbug.com/123');
109 assert.equal(group._annotation.bug, 'https://crbug.com/123');
110 assert.equal(group.bugLabel, 'Bug 123');
115 it('should support URLs', function(done) {
116 var group = new CTFailureGroup('', new CTStepFailureGroupData([newFailureWithAnnotation()]));
117 group.setBug('https://foobar.com/?id=876&x=y').then(function() {
118 assert.equal(group.bug, 'https://foobar.com/?id=876&x=y');
119 assert.equal(group._annotation.bug, 'https://foobar.com/?id=876&x=y');
120 assert.equal(group.bugLabel, 'Bug 876');
126 describe('clearBug', function() {
127 it('should work', function(done) {
128 var group = new CTFailureGroup('', new CTStepFailureGroupData([]));
129 group.setBug('123').then(function() {
130 group.clearBug().then(function() {
131 assert.isUndefined(group.bug);
132 assert.isUndefined(group.bugLabel);
133 assert.notProperty(group._annotation, 'bug');
140 describe('annotations', function() {
141 it('should have sensible defaults', function() {
142 var group = new CTFailureGroup('', new CTStepFailureGroupData([]));
143 assert.deepEqual(group._annotation, {});
144 assert.isFalse(group.isSnoozed);
145 assert.isUndefined(group.bug);
146 assert.isUndefined(group.bugLabel);
149 it('should compute properties', function() {
150 var group = new CTFailureGroup('', new CTStepFailureGroupData([newFailureWithAnnotation(
151 {snoozeTime: Date.now() + 1000 * 1000, bug: 'https://crbug.com/123'})]));
152 assert.isTrue(group.isSnoozed);
153 assert.equal(group.bug, 'https://crbug.com/123');
156 it('should ignore snoozeTime unless it is present on all alerts', function() {
157 var notSnoozedMultipleAlerts = new CTFailureGroup('', new CTStepFailureGroupData([
158 new CTStepFailure('step', 'reason', [
159 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}},
163 var notSnoozedMultipleFailures = new CTFailureGroup('', new CTStepFailureGroupData([
164 new CTStepFailure('step', 'reason', [
165 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}},
167 new CTStepFailure('step', 'reason', [
171 var snoozedMultipleAlerts = new CTFailureGroup('', new CTStepFailureGroupData([
172 new CTStepFailure('step', 'reason', [
173 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}},
174 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}},
177 var snoozedMultipleFailures = new CTFailureGroup('', new CTStepFailureGroupData([
178 new CTStepFailure('step', 'reason', [
179 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}},
181 new CTStepFailure('step', 'reason', [
182 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}},
185 assert.isFalse(notSnoozedMultipleAlerts.isSnoozed);
186 assert.isFalse(notSnoozedMultipleFailures.isSnoozed);
187 assert.isTrue(snoozedMultipleAlerts.isSnoozed);
188 assert.isTrue(snoozedMultipleFailures.isSnoozed);
191 it('should use the earliest snoozeTime of all alerts', function() {
192 var timeFuture = Date.now() + 1000 * 1000;
193 var timePast = Date.now() - 1000 * 1000;
195 var notSnoozed = new CTFailureGroup('', new CTStepFailureGroupData([
196 new CTStepFailure('step', 'reason', [
197 {key: 'a', annotation: {snoozeTime: timeFuture}},
198 {key: 'b', annotation: {snoozeTime: timePast}},
202 assert.isFalse(notSnoozed.isSnoozed);
205 it('should be persisted', function(done) {
206 var group = new CTFailureGroup('', new CTStepFailureGroupData(
207 [newFailureWithAnnotation(), newFailureWithAnnotation()]));
208 group.snoozeUntil(123).then(function() {
209 group.setBug('456').then(function() {
210 CTFailureGroup.fetchAnnotations().then(function(annotations) {
211 assert.deepEqual(annotations[group.data.failures[0].keys()[0]], {snoozeTime: 123, bug: 'https://crbug.com/456'});
212 assert.deepEqual(annotations[group.data.failures[1].keys()[0]], {snoozeTime: 123, bug: 'https://crbug.com/456'});