Blame view

src/core/pyros_django/scheduler/tests.py 29.1 KB
7a1effdd   haribo   scheduler app cre...
1
from django.test import TestCase
ddf59dd4   haribo   Remaniement :
2
3
from scheduler.Scheduler import Scheduler
from common.models import *
a2283bf3   haribo   Date: 20/05/2016
4
from scheduler.simulator import Simulator
7a1effdd   haribo   scheduler app cre...
5

f49b7078   Etienne Pallier   Bugfix tests and ...
6
7
import os

a2283bf3   haribo   Date: 20/05/2016
8
SIMULATION_FILE = 'file:./scheduler/sequences_cador.html'
b87b6d9b   haribo   Finished tests fo...
9

bca9a283   Jeremy   Reworked the sche...
10

b87b6d9b   haribo   Finished tests fo...
11
class SchedulerTest(TestCase):
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
12
    fixtures = ['tests/common_test_TZ.json']
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
13
    # (EP) Create a fixture in memory with 1 scheduler, 3 requests belonging to 3 different users
b87b6d9b   haribo   Finished tests fo...
14
15
16
17
18
19
    def setUp(self):
        '''
            Creates the scheduler
            Creates 3 users (and associated needs)
            Creates 3 requests

94082e77   haribo   Date: 03/06/2016
20
            Creates associated needs : scientific program, country, user_level
b87b6d9b   haribo   Finished tests fo...
21
        '''
94336356   haribo   Added starting fi...
22

b87b6d9b   haribo   Finished tests fo...
23
        self.scheduler = Scheduler()
94336356   haribo   Added starting fi...
24

7a79e25b   haribo   Date: 19/05/2016
25
        self.scheduler.max_overhead = 1
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
26
27
        institute = Institute.objects.get(id=1)
        scipro = ScientificProgram.objects.get(id=1)
b87b6d9b   haribo   Finished tests fo...
28
        country = Country.objects.create()
94082e77   haribo   Date: 03/06/2016
29
        user_level = UserLevel.objects.create()
94336356   haribo   Added starting fi...
30

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
31
32
33
        self.usr1 = PyrosUser.objects.create(username="toto", country=country, institute=institute)
        self.usr2 = PyrosUser.objects.create(username="titi", country=country, institute=institute)
        self.usr3 = PyrosUser.objects.create(username="tata", country=country, institute=institute)
05f66454   ALEXIS-PC\alexis   adding and updati...
34
35
36
        for user in PyrosUser.objects.all():
            # associate each user to the same userlevel
            UserLevel.objects.all()[0].pyros_users.add(user)
ee2c4543   Etienne Pallier   Bugfix Monitoring...
37
38
39
        self.req1 = Request.objects.create(pyros_user=self.usr1, scientific_program=scipro)
        self.req2 = Request.objects.create(pyros_user=self.usr2, scientific_program=scipro)
        self.req3 = Request.objects.create(pyros_user=self.usr3, scientific_program=scipro)
94336356   haribo   Added starting fi...
40

b87b6d9b   haribo   Finished tests fo...
41
42
43
44
45
    def test_basic_3_seq(self):
        '''
            goal : test if 3 distinct sequences are put into the planning
            conditions : the sequence have the same priority, and have no jd overlap
        '''
94336356   haribo   Added starting fi...
46

b87b6d9b   haribo   Finished tests fo...
47
        print("\n===== TEST_BASIC_3_SEQ =====\n")
94336356   haribo   Added starting fi...
48

b87b6d9b   haribo   Finished tests fo...
49
50
51
52
        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 10

        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
53
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
54
                                       name="seq1", jd1=0, jd2=2, priority=1, t_prefered=-1, duration=1)
4b503f5c   jeremy   Update installer ...
55
        seq2 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
56
                                       name="seq2", jd1=4, jd2=6, priority=1, t_prefered=-1, duration=1)
4b503f5c   jeremy   Update installer ...
57
        seq3 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
58
59
                                       name="seq3", jd1=7, jd2=9, priority=1, t_prefered=-1, duration=1)

b87b6d9b   haribo   Finished tests fo...
60
        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
61
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
62

7a79e25b   haribo   Date: 19/05/2016
63
64
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
65
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
94336356   haribo   Added starting fi...
66

bca9a283   Jeremy   Reworked the sche...
67
68
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
69
70
71
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
72
73

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
74

7a79e25b   haribo   Date: 19/05/2016
75
76
77
78
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 2)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
79

7a79e25b   haribo   Date: 19/05/2016
80
81
82
83
        self.assertEqual(shs2.tsp, 4)
        self.assertEqual(shs2.tep, 5)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 1)
b87b6d9b   haribo   Finished tests fo...
84

7a79e25b   haribo   Date: 19/05/2016
85
86
87
88
        self.assertEqual(shs3.tsp, 7)
        self.assertEqual(shs3.tep, 8)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 1)
b87b6d9b   haribo   Finished tests fo...
89

b87b6d9b   haribo   Finished tests fo...
90
91
92
93
94
    def test_3_seq_with_quotas(self):
        '''
            goal : test if the quotas are decreased
            conditions : the sequences have the same priority, and various durations
        '''
94336356   haribo   Added starting fi...
95

b87b6d9b   haribo   Finished tests fo...
96
97
98
99
100
        print("\n===== TEST_3_SEQ_WITH_QUOTAS =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 100

b87b6d9b   haribo   Finished tests fo...
101
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
102
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
7a79e25b   haribo   Date: 19/05/2016
103
                                       name="seq1", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=3)
4b503f5c   jeremy   Update installer ...
104
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
7a79e25b   haribo   Date: 19/05/2016
105
                                       name="seq2", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
106
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
7a79e25b   haribo   Date: 19/05/2016
107
                                       name="seq3", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=5)
94336356   haribo   Added starting fi...
108

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
109
110
        # TODO : change quota gestion with rework of PyrosUser table
        """ seq1.request.pyros_user.quota = 100
b87b6d9b   haribo   Finished tests fo...
111
112
113
114
        seq1.request.pyros_user.save()
        seq2.request.pyros_user.quota = 100
        seq2.request.pyros_user.save()
        seq3.request.pyros_user.quota = 100
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
115
        seq3.request.pyros_user.save() """
b87b6d9b   haribo   Finished tests fo...
116
117

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
118
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
119

7a79e25b   haribo   Date: 19/05/2016
120
121
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
122
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
123
124
125
126
127
128

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks sequence owners' quotas '''
94336356   haribo   Added starting fi...
129

b87b6d9b   haribo   Finished tests fo...
130
131
        self.assertEqual(nbPlanned, 3)

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
132
        """
b87b6d9b   haribo   Finished tests fo...
133
134
        self.assertEqual(seq1.request.pyros_user.quota, 100 - 3)
        self.assertEqual(seq2.request.pyros_user.quota, 100 - 10)
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
135
136
        self.assertEqual(seq3.request.pyros_user.quota, 100 - 5) 
        """
b87b6d9b   haribo   Finished tests fo...
137
138
139
140
141
142

    def test_4_seq_insufficient_quotas(self):
        '''
            goal : test if an insufficient quota blocks sequence programmation
            conditions : the sequences have the same priority, a user has 2 sequence, the others have 1 Sequence
        '''
94336356   haribo   Added starting fi...
143

b87b6d9b   haribo   Finished tests fo...
144
145
146
147
148
        print("\n===== TEST_4_SEQ_INSUFFICIENT_QUOTAS =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 100

b87b6d9b   haribo   Finished tests fo...
149
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
150
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
151
                                       name="seq1", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=3)
4b503f5c   jeremy   Update installer ...
152
        seq2 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
153
                                       name="seq2", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
154
        seq3 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
155
                                       name="seq3", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
156
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
157
158
                                       name="seq4", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=15)

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
159
        """
b87b6d9b   haribo   Finished tests fo...
160
161
162
163
164
165
        seq1.request.pyros_user.quota = 11
        seq1.request.pyros_user.save()
        seq3.request.pyros_user.quota = 10
        seq3.request.pyros_user.save()
        seq4.request.pyros_user.quota = 14
        seq4.request.pyros_user.save()
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
166
        """
b87b6d9b   haribo   Finished tests fo...
167
168

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
169
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
170

7a79e25b   haribo   Date: 19/05/2016
171
172
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
173
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
174
175
176
177
178
179
180

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")
        seq4 = Sequence.objects.get(name="seq4")

        ''' checks sequence owners' quotas '''
94336356   haribo   Added starting fi...
181

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
182
183
        # TODO : adapt test to new quotas
        """
b87b6d9b   haribo   Finished tests fo...
184
185
186
187
188
        self.assertEqual(nbPlanned, 2)

        self.assertEqual(seq1.request.pyros_user.quota, 11 - 3 - 0)
        self.assertEqual(seq3.request.pyros_user.quota, 10 - 10)
        self.assertEqual(seq4.request.pyros_user.quota, 14 - 0)
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
189
        """
b87b6d9b   haribo   Finished tests fo...
190
191
192
193
194
    def test_3_seq_priority(self):
        '''
            goal : test if the priority is taken into account when there isn't enough room
            conditions : sequences have different priorities, are visible the whole night and can't be all put
        '''
94336356   haribo   Added starting fi...
195

b87b6d9b   haribo   Finished tests fo...
196
197
198
199
200
        print("\n===== TEST_3_SEQ_PRIORITY =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 20

b87b6d9b   haribo   Finished tests fo...
201
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
202
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
203
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
204
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
205
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
4b503f5c   jeremy   Update installer ...
206
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
207
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=10)
b87b6d9b   haribo   Finished tests fo...
208
209

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
210
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
211

7a79e25b   haribo   Date: 19/05/2016
212
213
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
214
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
215

7a79e25b   haribo   Date: 19/05/2016
216
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
b87b6d9b   haribo   Finished tests fo...
217
218

        ''' checks which sequence is planned '''
94336356   haribo   Added starting fi...
219

b87b6d9b   haribo   Finished tests fo...
220
221
        self.assertEqual(nbPlanned, 1)

4b503f5c   jeremy   Update installer ...
222
        self.assertEqual(shs2.status, Sequence.PLANNED)
b87b6d9b   haribo   Finished tests fo...
223

b87b6d9b   haribo   Finished tests fo...
224
225
226
227
228
    def test_3_seq_priority_overlap(self):
        '''
            goal : test if the sequences are arranged according to the priorities
            conditions : sequences have different priorities, are visible the whole night and can be all put (enough room)
        '''
94336356   haribo   Added starting fi...
229

b87b6d9b   haribo   Finished tests fo...
230
231
232
233
234
        print("\n===== TEST_3_SEQ_PRIORITY_OVERLAP =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
235
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
236
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
237
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
238
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
239
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
4b503f5c   jeremy   Update installer ...
240
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
241
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=12)
b87b6d9b   haribo   Finished tests fo...
242
243

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
244
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
245

7a79e25b   haribo   Date: 19/05/2016
246
247
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
248
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
249

7a79e25b   haribo   Date: 19/05/2016
250
251
252
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
253
254

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
255

b87b6d9b   haribo   Finished tests fo...
256
257
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
258
259
260
261
        self.assertEqual(shs2.tsp, 1)
        self.assertEqual(shs2.tep, 12)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 0)
94336356   haribo   Added starting fi...
262

7a79e25b   haribo   Date: 19/05/2016
263
264
265
266
        self.assertEqual(shs1.tsp, 13)
        self.assertEqual(shs1.tep, 23)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
267

7a79e25b   haribo   Date: 19/05/2016
268
269
270
271
        self.assertEqual(shs3.tsp, 24)
        self.assertEqual(shs3.tep, 36)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 200 - shs3.tep)
b87b6d9b   haribo   Finished tests fo...
272
273
274
275
276
277

    def test_3_seq_t_prefered(self):
        '''
            goal: test if the sequences are wall_arranged with t_prefered
            conditions : various t_prefered that should put the sequences at the beginning, the middle and the end of the night
        '''
94336356   haribo   Added starting fi...
278

b87b6d9b   haribo   Finished tests fo...
279
280
281
282
283
        print("\n===== TEST_3_SEQ_T_PREFERED =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
284
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
285
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
286
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=11, duration=20)
4b503f5c   jeremy   Update installer ...
287
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
288
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
4b503f5c   jeremy   Update installer ...
289
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
290
                                       name="seq3", jd1=0, jd2=200, priority=1, t_prefered=191, duration=20)
b87b6d9b   haribo   Finished tests fo...
291
292

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
293
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
294

7a79e25b   haribo   Date: 19/05/2016
295
296
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
297
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
298

bca9a283   Jeremy   Reworked the sche...
299
300
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
301
302
303
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
304
305

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
306

bca9a283   Jeremy   Reworked the sche...
307
        self.scheduler.logSchedule()
b87b6d9b   haribo   Finished tests fo...
308

7a79e25b   haribo   Date: 19/05/2016
309
310
311
312
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 21)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, shs2.tsp - 1 - shs1.tep)
94336356   haribo   Added starting fi...
313

7a79e25b   haribo   Date: 19/05/2016
314
315
316
317
        self.assertEqual(shs2.tsp, 90)
        self.assertEqual(shs2.tep, 110)
        self.assertEqual(shs2.deltaTL, shs1.deltaTR)
        self.assertEqual(shs2.deltaTR, shs3.tsp - 1 - shs2.tep)
b87b6d9b   haribo   Finished tests fo...
318

7a79e25b   haribo   Date: 19/05/2016
319
320
321
322
        self.assertEqual(shs3.tsp, 180)
        self.assertEqual(shs3.tep, 200)
        self.assertEqual(shs3.deltaTL, shs2.deltaTR)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
323
324
325
326
327
328

    def test_3_seq_t_prefered_priority(self):
        '''
            goal: test if the sequences are wall_arranged with t_prefered and priority
            conditions : various t_prefered that should put the sequences the middle of the night, according to priority
        '''
94336356   haribo   Added starting fi...
329

b87b6d9b   haribo   Finished tests fo...
330
331
332
333
334
        print("\n===== TEST_3_SEQ_T_PREFERED_PRIORITY =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
335
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
336
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
337
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
4b503f5c   jeremy   Update installer ...
338
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
339
                                       name="seq2", jd1=0, jd2=200, priority=0, t_prefered=100, duration=20)
4b503f5c   jeremy   Update installer ...
340
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
341
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=100, duration=20)
b87b6d9b   haribo   Finished tests fo...
342
343

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
344
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
345

7a79e25b   haribo   Date: 19/05/2016
346
347
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
348
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
349

bca9a283   Jeremy   Reworked the sche...
350
351
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
352
353
354
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
355
356

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
357

b87b6d9b   haribo   Finished tests fo...
358

7a79e25b   haribo   Date: 19/05/2016
359
360
        self.assertEqual(shs1.tsp, 69)
        self.assertEqual(shs1.tep, 89)
92039557   haribo   Minor fix : t_pre...
361
        self.assertEqual(shs1.deltaTL, 68)
7a79e25b   haribo   Date: 19/05/2016
362
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
363

7a79e25b   haribo   Date: 19/05/2016
364
365
366
        self.assertEqual(shs2.tsp, 90)
        self.assertEqual(shs2.tep, 110)
        self.assertEqual(shs2.deltaTL, 0)
92039557   haribo   Minor fix : t_pre...
367
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
368

92039557   haribo   Minor fix : t_pre...
369
370
371
372
        self.assertEqual(shs3.tsp, 111)
        self.assertEqual(shs3.tep, 131)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 200 - shs3.tep)
b87b6d9b   haribo   Finished tests fo...
373
374
375
376
377

    def test_3_seq_move_left(self):
        '''
            goal: test if a sequence can move to the left to let another one
            conditions : use priorities to place 2 sequences with an interval between, then try to put a bigger sequence in it
94336356   haribo   Added starting fi...
378
379
        '''

b87b6d9b   haribo   Finished tests fo...
380
381
382
        print("\n===== TEST_3_SEQ_MOVE_LEFT =====\n")

        self.scheduler.schedule.plan_start = 0
7a79e25b   haribo   Date: 19/05/2016
383
        self.scheduler.schedule.plan_end = 58
b87b6d9b   haribo   Finished tests fo...
384

b87b6d9b   haribo   Finished tests fo...
385
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
386
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
387
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
4b503f5c   jeremy   Update installer ...
388