Add a test for changes that trigger multiple pipelines.

Change-Id: I147491d2c08fa1040f41f0c299113e3eb8968252
Reviewed-on: https://review.openstack.org/29158
Reviewed-by: Antoine Musso <hashar@free.fr>
Reviewed-by: Jeremy Stanley <fungi@yuggoth.org>
Approved: Clark Boylan <clark.boylan@gmail.com>
Reviewed-by: Clark Boylan <clark.boylan@gmail.com>
Tested-by: Jenkins
diff --git a/tests/fixtures/layout.yaml b/tests/fixtures/layout.yaml
index ecdd2da..ed36a18 100644
--- a/tests/fixtures/layout.yaml
+++ b/tests/fixtures/layout.yaml
@@ -37,6 +37,25 @@
         approval: 
           - approved: 1
 
+  - name: dup1
+    manager: IndependentPipelineManager
+    trigger:
+      - event: change-restored
+    success:
+      verified: 1
+    failure:
+      verified: -1
+
+  - name: dup2
+    manager: IndependentPipelineManager
+    trigger:
+      - event: change-restored
+    success:
+      verified: 1
+    failure:
+      verified: -1
+
+
 jobs:
   - name: ^.*-merge$
     failure-message: Unable to merge change
@@ -68,6 +87,10 @@
         - project-testfile
     post:
       - project-post
+    dup1:
+      - project-test1
+    dup2:
+      - project-test1
 
   - name: org/project1
     check:
diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py
index 2d5fff3..1951c37 100644
--- a/tests/test_scheduler.py
+++ b/tests/test_scheduler.py
@@ -176,6 +176,7 @@
         self.depends_on_change = None
         self.needed_by_changes = []
         self.fail_merge = False
+        self.messages = []
         self.data = {
             'branch': branch,
             'comments': [],
@@ -241,6 +242,19 @@
                  "uploader": {"name": "User Name"}}
         return event
 
+    def getChangeRestoredEvent(self):
+        event = {"type": "change-restored",
+                 "change": {"project": self.project,
+                            "branch": self.branch,
+                            "id": "I5459869c07352a31bfb1e7a8cac379cabfcb25af",
+                            "number": str(self.number),
+                            "subject": self.subject,
+                            "owner": {"name": "User Name"},
+                            "url": "https://hostname/3"},
+                 "restorer": {"name": "User Name"},
+                 "reason": ""}
+        return event
+
     def addApproval(self, category, value):
         approval = {'description': self.categories[category][0],
                     'type': category,
@@ -372,6 +386,7 @@
     def review(self, project, changeid, message, action):
         number, ps = changeid.split(',')
         change = self.changes[int(number)]
+        change.messages.append(message)
         if 'submit' in action:
             change.setMerged()
         if message:
@@ -832,6 +847,34 @@
         self.assertReportedStat(
             'zuul.pipeline.gate.org.project.total_changes', '1|c')
 
+    def test_duplicate_pipelines(self):
+        "Test that a change matching multiple pipelines works"
+        A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
+        self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
+        self.waitUntilSettled()
+        jobs = self.fake_jenkins.job_history
+
+        print jobs
+        print A.messages
+
+        self.assertEmptyQueues()
+
+        assert len(jobs) == 2
+        jobs[0].name == 'project-test1'
+        jobs[1].name == 'project-test1'
+
+        assert len(A.messages) == 2
+        if 'dup1/project-test1' in A.messages[0]:
+            assert 'dup1/project-test1' in A.messages[0]
+            assert 'dup2/project-test1' not in A.messages[0]
+            assert 'dup1/project-test1' not in A.messages[1]
+            assert 'dup2/project-test1' in A.messages[1]
+        else:
+            assert 'dup1/project-test1' in A.messages[1]
+            assert 'dup2/project-test1' not in A.messages[1]
+            assert 'dup1/project-test1' not in A.messages[0]
+            assert 'dup2/project-test1' in A.messages[0]
+
     def test_parallel_changes(self):
         "Test that changes are tested in parallel and merged in series"
         self.fake_jenkins.hold_jobs_in_build = True