forked from green-coding-solutions/green-metrics-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_frontend.py
More file actions
1691 lines (1310 loc) · 89.5 KB
/
Copy pathtest_frontend.py
File metadata and controls
1691 lines (1310 loc) · 89.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import pytest
import time
import requests
import uuid
import json
GMT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../..')
from lib.global_config import GlobalConfig
from lib.user import User
from lib.db import DB
from lib.encryption import ENCRYPTED_VALUE_PREFIX
from tests import test_functions as Tests
from playwright.sync_api import sync_playwright, TimeoutError as PlaywrightTimeoutError
from datetime import datetime, timedelta
from api.object_specifications import CI_Measurement, CI_MeasurementV3
page = None
context = None
playwright = None
browser = None
API_URL = GlobalConfig().config['cluster']['api_url'] # will be pre-loaded with test-config.yml due to conftest.py
## Shared Playwright setup for all tests
@pytest.fixture(autouse=True, scope='module')
def setup_playwright():
"""Start Playwright once for the entire module"""
# before
global playwright #pylint: disable=global-statement
playwright = sync_playwright().start()
yield
# after
playwright.stop()
# Browser setup for each test
@pytest.fixture(autouse=True)
def setup_browser(setup_playwright): #pylint: disable=unused-argument,redefined-outer-name
"""
Set up browser for each test
We must close the browser to clear localStorage
"""
global page #pylint: disable=global-statement
global context #pylint: disable=global-statement
global browser #pylint: disable=global-statement
browser = playwright.firefox.launch(
headless=True, # True is default, set to False to use the browser in headful mode
# slow_mo=50,
)
context = browser.new_context(viewport={"width": 1920, "height": 5600})
page = context.new_page()
page.set_default_timeout(3_000)
page.on("pageerror", handle_page_error)
yield
page.close()
context.close()
browser.close()
def handle_page_error(exception):
# we really would love to execute page.screenshot() here, but weirdly this leads to the test passing if page is broken ... even a try/except block does not help ...
raise RuntimeError("JS error occured on page:", exception)
## Fixture for tests that need demo data
@pytest.fixture()
def use_demo_data():
"""Import demo data for standard frontend tests"""
Tests.import_demo_data()
yield
Tests.reset_db()
def insert_demo_run_with_custom_sci_phase_stats():
run_id = str(uuid.uuid4())
phases = [
{"start": 1735933199000000, "name": "[BASELINE]", "hidden": False, "end": 1735933200000000},
{"start": 1735933200000000, "name": "[RUNTIME]", "hidden": False, "end": 1735933205000000},
{"start": 1735933200000100, "name": "Hit Generator", "hidden": False, "end": 1735933205000000},
]
usage_scenario = {
"name": "Custom SCI Demo",
"author": "Tests",
"description": "demo",
"custom_metrics": {
"custom_my_coolness": {"unit": "gigacools"},
"custom_hits": {"unit": "Hits", "sci": True},
},
}
DB().query(
"""
INSERT INTO runs ("id","name","uri","branch","commit_hash","usage_scenario","usage_scenario_variables","filename","machine_id","user_id","failed","logs","phases","created_at","updated_at")
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,NOW(),NOW())
""",
params=(
run_id,
'Custom SCI Demo Run',
'/demo/custom-sci',
'main',
'deadbeef123456789abcdef',
json.dumps(usage_scenario),
json.dumps({}),
'tests/data/usage_scenarios/stress_custom_metrics.yml',
1,
1,
False,
json.dumps({}),
json.dumps(phases),
),
)
DB().query(
"""
INSERT INTO phase_stats ("run_id","metric","detail_name","phase","value","type","max_value","min_value","sampling_rate_avg","sampling_rate_max","sampling_rate_95p","unit","hidden","created_at","updated_at")
VALUES
(%s,E'phase_time_syscall_system',E'[SYSTEM]',E'000_[BASELINE]',1000000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'us',FALSE,NOW(),NULL),
(%s,E'embodied_carbon_share_machine',E'[SYSTEM]',E'000_[BASELINE]',10000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'ug',FALSE,NOW(),NULL),
(%s,E'phase_time_syscall_system',E'[SYSTEM]',E'001_Hit Generator',5000000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'us',FALSE,NOW(),NULL),
(%s,E'custom_hits',E'test-container',E'001_Hit Generator',1000,E'TOTAL',1000,1000,100000,100000,100000,E'Hits',FALSE,NOW(),NULL),
(%s,E'custom_hits_sci_global',E'test-container',E'001_Hit Generator',120000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'ugCO2e/Hits',FALSE,NOW(),NULL),
(%s,E'custom_my_coolness',E'test-container',E'001_Hit Generator',42,E'TOTAL',42,42,100000,100000,100000,E'gigacools',FALSE,NOW(),NULL),
(%s,E'phase_time_syscall_system',E'[SYSTEM]',E'002_[RUNTIME]',5000000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'us',FALSE,NOW(),NULL),
(%s,E'custom_hits',E'test-container',E'002_[RUNTIME]',1000,E'TOTAL',1000,1000,100000,100000,100000,E'Hits',FALSE,NOW(),NULL),
(%s,E'custom_hits_sci_global',E'test-container',E'002_[RUNTIME]',120000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'ugCO2e/Hits',FALSE,NOW(),NULL),
(%s,E'custom_my_coolness',E'test-container',E'002_[RUNTIME]',42,E'TOTAL',42,42,100000,100000,100000,E'gigacools',FALSE,NOW(),NULL)
""",
params=(run_id, run_id, run_id, run_id, run_id, run_id, run_id, run_id, run_id, run_id),
)
return run_id
def insert_demo_run_with_component_carbon_phase_stats():
# Mirrors a run where the carbon post-processing has created operational carbon values
# not only for the machine, but for all energy components (CPU, DRAM, ...) as well.
run_id = str(uuid.uuid4())
phases = [
{"start": 1735933199000000, "name": "[BASELINE]", "hidden": False, "end": 1735933200000000},
{"start": 1735933200000000, "name": "[RUNTIME]", "hidden": False, "end": 1735933205000000},
{"start": 1735933200000100, "name": "Hit Generator", "hidden": False, "end": 1735933205000000},
]
usage_scenario = {
"name": "Component Carbon Demo",
"author": "Tests",
"description": "demo",
}
DB().query(
"""
INSERT INTO runs ("id","name","uri","branch","commit_hash","usage_scenario","usage_scenario_variables","filename","machine_id","user_id","failed","logs","phases","created_at","updated_at")
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,NOW(),NOW())
""",
params=(
run_id,
'Component Carbon Demo Run',
'/demo/component-carbon',
'main',
'deadbeef123456789abcdef',
json.dumps(usage_scenario),
json.dumps({}),
'tests/data/usage_scenarios/stress_application.yml',
1,
1,
False,
json.dumps({}),
json.dumps(phases),
),
)
DB().query(
"""
INSERT INTO phase_stats ("run_id","metric","detail_name","phase","value","type","max_value","min_value","sampling_rate_avg","sampling_rate_max","sampling_rate_95p","unit","hidden","created_at","updated_at")
VALUES
(%s,E'phase_time_syscall_system',E'[SYSTEM]',E'000_[BASELINE]',1000000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'us',FALSE,NOW(),NULL),
(%s,E'phase_time_syscall_system',E'[SYSTEM]',E'001_Hit Generator',5000000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'us',FALSE,NOW(),NULL),
(%s,E'cpu_carbon_rapl_msr_component',E'Package_0',E'001_Hit Generator',2500000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'ugCO2e',FALSE,NOW(),NULL),
(%s,E'memory_carbon_rapl_msr_component',E'Package_0',E'001_Hit Generator',1500000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'ugCO2e',FALSE,NOW(),NULL),
(%s,E'phase_time_syscall_system',E'[SYSTEM]',E'002_[RUNTIME]',5000000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'us',FALSE,NOW(),NULL),
(%s,E'cpu_carbon_rapl_msr_component',E'Package_0',E'002_[RUNTIME]',2500000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'ugCO2e',FALSE,NOW(),NULL),
(%s,E'memory_carbon_rapl_msr_component',E'Package_0',E'002_[RUNTIME]',1500000,E'TOTAL',NULL,NULL,NULL,NULL,NULL,E'ugCO2e',FALSE,NOW(),NULL)
""",
params=(run_id, run_id, run_id, run_id, run_id, run_id, run_id),
)
return run_id
@pytest.mark.usefixtures('use_demo_data')
class TestFrontendFunctionality:
"""Functional frontend tests"""
def test_home(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
value = page.locator("div.ui.cards.link > div.ui.card:nth-child(1) a.header").text_content()
assert value== 'ScenarioRunner'
value = page.locator("#scenario-runner-count").text_content()
assert value== '8'
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
value = page.locator("div.ui.cards.link > div.ui.card:nth-child(2) a.header").text_content()
assert value== 'Eco CI'
def test_runs(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/runs.html')
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
value = page.locator("#runs-and-repos-table > tbody tr:nth-child(3) > td:nth-child(1) > a").text_content()
assert value== 'Stress Test #2'
def test_eco_ci_demo_data(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Eco CI", exact=True).click()
page.wait_for_load_state("load") # ALL JS should be done
page.locator("#ci-repositories-table > tbody > tr:nth-child(1) > td > div > div.title").click()
page.locator('#DataTables_Table_0 > tbody > tr > td:first-child > a').click()
page.wait_for_load_state("load") # ALL JS should be done
page.locator("input[name=range_start]").fill('2024-09-11')
page.locator("input[name=range_end]").fill('2024-10-11')
page.get_by_role("button", name="Refresh").click()
time.sleep(2) # wait for new data to render
energy_avg_all_steps = page.locator("#label-stats-table-avg > tr:nth-child(1) > td:nth-child(2)").text_content()
assert energy_avg_all_steps.strip() == '28.60 J (± 3.30%)'
time_avg_all_steps = page.locator("#label-stats-table-avg > tr:nth-child(1) > td:nth-child(3)").text_content()
assert time_avg_all_steps.strip() == '12.80 s (± 3.49%)'
cpu_avg_all_steps = page.locator("#label-stats-table-avg > tr:nth-child(1) > td:nth-child(4)").text_content()
assert cpu_avg_all_steps.strip() == '44.73% (± 10.65%%)'
grid_all_steps = page.locator("#label-stats-table-avg > tr:nth-child(1) > td:nth-child(5)").text_content()
assert grid_all_steps.strip() == '494.20 gCO2/kWh (± 5.47%)'
carbon_all_steps = page.locator("#label-stats-table-avg > tr:nth-child(1) > td:nth-child(6)").text_content()
assert carbon_all_steps.strip() == '0.016 gCO2e (± 5.71%)'
count_all_steps = page.locator("#label-stats-table-avg > tr:nth-child(1) > td:nth-child(7)").text_content()
assert count_all_steps.strip() == '5'
energy_avg_single = page.locator("#label-stats-table-avg > tr:nth-child(2) > td:nth-child(2)").text_content()
assert energy_avg_single.strip() == '24.14 J (± 1.88%)'
time_avg_single = page.locator("#label-stats-table-avg > tr:nth-child(2) > td:nth-child(3)").text_content()
assert time_avg_single.strip() == '10.00 s (± 0.00%)'
cpu_avg_single = page.locator("#label-stats-table-avg > tr:nth-child(2) > td:nth-child(4)").text_content()
assert cpu_avg_single.strip() == '49.60% (± 5.06%%)'
grid_single = page.locator("#label-stats-table-avg > tr:nth-child(2) > td:nth-child(5)").text_content()
assert grid_single.strip() == '494.20 gCO2/kWh (± 5.47%)'
carbon_single = page.locator("#label-stats-table-avg > tr:nth-child(2) > td:nth-child(6)").text_content()
assert carbon_single.strip() == '0.0134 gCO2e (± 5.27%)'
count_single = page.locator("#label-stats-table-avg > tr:nth-child(2) > td:nth-child(7)").text_content()
assert count_single.strip() == '5'
def open_and_assert_ci_stats(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Eco CI", exact=True).click()
page.locator("#ci-repositories-table > tbody > tr:nth-child(1) > td > div > div.title").click()
page.locator('#DataTables_Table_0 > tbody > tr > td:first-child > a').click()
page.wait_for_load_state("load")
energy_avg_all_steps = page.locator(
"#label-stats-table-avg > tr:nth-child(1) > td:nth-child(2)"
).text_content()
assert energy_avg_all_steps.strip() == '78.00 J (± 0.00%)'
carbon_all_steps = page.locator(
"#label-stats-table-avg > tr:nth-child(1) > td:nth-child(6)"
).text_content()
assert carbon_all_steps.strip() == '0.9704 gCO2e (± 0.00%)'
carbon_all_steps = page.locator(
"#label-stats-table-avg > tr:nth-child(1) > td:nth-child(3)"
).text_content()
assert carbon_all_steps.strip() == '0.11 s (± 0.00%)'
def test_eco_ci_adding_data(self):
for index in range(1,4):
measurement = CI_Measurement(energy_uj=(13_000_000*index),
repo='testRepo',
branch='testBranch',
cpu='testCPU',
cpu_util_avg=50,
commit_hash='1234asdf',
workflow='testWorkflow',
run_id='testRunID',
source='testSource',
label='testLabel',
duration_us=35323,
workflow_name='testWorkflowName',
lat="18.2972",
lon="77.2793",
city="Nine Mile",
carbon_intensity_g=100,
carbon_ug=323456
)
response = requests.post(f"{API_URL}/v2/ci/measurement/add", json=measurement.model_dump(), timeout=15)
assert response.status_code == 202, Tests.assertion_info('success', response.text)
self.open_and_assert_ci_stats()
def test_eco_ci_adding_data_v3(self):
for index in range(1, 4):
measurement = CI_MeasurementV3(energy_uj=(13_000_000 * index),
repo='testRepo',
branch='testBranch',
cpu='testCPU',
cpu_util_avg=50,
commit_hash='1234asdf',
workflow='testWorkflow',
run_id='testRunID',
source='testSource',
label='testLabel',
duration_us=35323,
workflow_name='testWorkflowName',
lat="18.2972",
lon="77.2793",
city="Nine Mile",
carbon_intensity_g=100,
carbon_ug=323456,
os_name='Linux',
cpu_arch='x86_64',
job_id='testJobID',
version='v1.2'
)
response = requests.post(f"{API_URL}/v3/ci/measurement/add", json=measurement.model_dump(), timeout=15)
assert response.status_code == 202, Tests.assertion_info('success', response.text)
self.open_and_assert_ci_stats()
def test_stats(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
with context.expect_page() as new_page_info:
page.get_by_role("link", name="Stress Test #1", exact=True).click()
# Get the new page (tab)
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
new_page.wait_for_load_state("networkidle")
assert new_page.locator("#runtime-hidden-info").is_hidden() is True
assert new_page.locator("#run-failed").is_hidden() is True
assert new_page.locator("#run-warnings").is_hidden() is True
# open details
new_page.locator('a.step[data-tab="[RUNTIME]"]').click()
new_page.locator('#runtime-steps phase-metrics .ui.accordion .title > a').first.click()
machine_energy_value = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.tab[data-tab="energy"] div.ui.blue.card.machine-energy > div.extra.content span.value.bold').text_content()
phase_duration = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.runtime > div.extra.content span.value.bold').text_content()
cpu_package_power = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.tab[data-tab="power"] div.ui.orange.card.cpu-power > div.extra.content span.value.bold').text_content()
embodied_carbon = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.embodied-carbon > div.extra.content span.value.bold').text_content()
network_traffic = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.network-traffic > div.extra.content span.value.bold').text_content()
network_data = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.network-data > div.extra.content span.value.bold').text_content()
assert machine_energy_value.strip() == '21.14'
assert phase_duration.strip() == '5.20'
assert cpu_package_power.strip() == '8.66'
assert embodied_carbon.strip() == '0.01'
assert network_traffic.strip() == '0.37'
assert network_data.strip() == '0.07'
# fetch time series
new_page.locator('button#fetch-time-series').click()
# expand charts
new_page.locator('div#chart-container .statistics-chart-card button.toggle-width')
for el in new_page.locator('div#chart-container .statistics-chart-card button.toggle-width').all():
el.click()
chart_label = new_page.locator("#chart-container > div:nth-child(3) > div > div.ui.left.floated.chart-title").text_content()
assert chart_label.strip() == 'CPU % via procfs'
table = new_page.locator(
"#runtime-steps > div.ui.bottom.attached.active.tab.segment "
"> div.ui.segment.secondary > phase-metrics "
"> div.ui.accordion > div.content.active > table > tbody"
)
# Phase Duration
assert cell(table, 1, 1).text_content().strip() == "Phase Duration"
assert cell(table, 1, 6).text_content().strip() == "5.20"
assert cell(table, 1, 7).text_content().strip() == "s"
assert cell(table, 1, 10).text_content().replace(" ", "").strip() == " -/\n-/\n-ms".strip()
# Network I/O
assert cell(table, 7, 1).text_content().strip() == "Network I/O"
assert cell(table, 7, 6).text_content().strip() == "0.07"
assert cell(table, 7, 6).inner_html().strip() == '<span title="71208 Bytes/s">0.07</span>'
assert cell(table, 7, 7).text_content().strip() == "MB/s"
assert cell(table, 7, 4).text_content().strip() == "gcb-alpine-stress"
# Network Traffic
assert cell(table, 8, 1).text_content().strip() == "Network Traffic"
assert cell(table, 8, 4).text_content().strip() == "gcb-alpine-stress"
assert cell(table, 8, 6).text_content().strip() == "0.37"
assert cell(table, 8, 6).inner_html().strip() == '<span title="367908 Bytes">0.37</span>'
# Machine Energy
assert cell(table, 9, 1).text_content().strip() == "Machine Energy"
assert cell(table, 9, 6).text_content().strip() == "21.14"
assert cell(table, 9, 7).text_content().strip() == "mWh"
assert cell(table, 9, 10).text_content().replace(" ", "").strip() == "99/\n100/\n101ms"
# Machine Power
assert cell(table, 10, 1).text_content().strip() == "Machine Power"
assert cell(table, 10, 6).text_content().strip() == "14.62"
assert cell(table, 10, 7).text_content().strip() == "W"
assert cell(table, 10, 10).text_content().replace(" ", "").strip() == "99/\n100/\n101ms"
# Network Transmission CO₂
assert cell(table, 13, 1).text_content().strip() == "Network Transmission CO₂"
assert cell(table, 13, 6).inner_html().strip() == (
'<span title="425 ug">0.00</span> '
'<span data-tooltip="Value is lower than rounding. Unrounded value is 425 ug" '
'data-position="bottom center" data-inverted=""><i class="question circle icon link"></i></span>'
)
assert cell(table, 13, 7).text_content().strip() == "g"
# click on baseline
new_page.locator('a.step[data-tab="[BASELINE]"]').click()
new_page.locator('div[data-tab="[BASELINE]"] .ui.accordion .title > a').click()
first_metric = new_page.locator("#main > div.ui.tab.attached.segment.secondary.active > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(8) > td:nth-child(1)").text_content()
assert first_metric.strip() == 'Machine CO₂ (embodied)'
first_value = new_page.locator("#main > div.ui.tab.attached.segment.secondary.active > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(8) > td:nth-child(6)").text_content()
assert first_value.strip() == '0.01'
first_unit = new_page.locator("#main > div.ui.tab.attached.segment.secondary.active > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(8) > td:nth-child(7)").text_content()
assert first_unit.strip() == 'g'
def test_stats_multi_network(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
with context.expect_page() as new_page_info:
page.get_by_role("link", name="Stress Test #1 - Copy with additional network - Phase Stats Stub only no metrics").click()
# Get the new page (tab)
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
new_page.wait_for_load_state("networkidle")
assert new_page.locator("#runtime-hidden-info").is_hidden() is True
assert new_page.locator("#run-failed").is_hidden() is True
assert new_page.locator("#run-warnings").is_hidden() is True
# open details
new_page.locator('a.step[data-tab="[RUNTIME]"]').click()
new_page.locator('#runtime-steps phase-metrics .ui.accordion .title > a').first.click()
machine_energy_value = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.tab[data-tab="energy"] div.ui.blue.card.machine-energy > div.extra.content span.value.bold').text_content()
phase_duration = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.runtime > div.extra.content span.value.bold').text_content()
cpu_package_power = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.tab[data-tab="power"] div.ui.orange.card.cpu-power > div.extra.content span.value.bold').text_content()
embodied_carbon = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.embodied-carbon > div.extra.content span.value.bold').text_content()
network_traffic_node = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.network-traffic > div.extra.content span.value.bold')
network_data_node = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.network-data > div.extra.content span.value.bold')
assert machine_energy_value.strip() == '21.14'
assert phase_duration.strip() == '5.20'
assert cpu_package_power.strip() == '8.66'
assert embodied_carbon.strip() == '0.01'
assert network_traffic_node.inner_html().strip() == '0.41 (<i class="window restore outline icon" title="This is an aggregate value based on multiple sources. Please check metrics table for individual values."></i>)'
assert network_data_node.inner_html().strip() == '0.16 (<i class="window restore outline icon" title="This is an aggregate value based on multiple sources. Please check metrics table for individual values."></i>)'
table = new_page.locator(
"#runtime-steps > div.ui.bottom.attached.active.tab.segment "
"> div.ui.segment.secondary > phase-metrics "
"> div.ui.accordion > div.content.active > table > tbody"
)
# Phase Duration
assert cell(table, 1, 1).text_content().strip() == "Phase Duration"
assert cell(table, 1, 6).text_content().strip() == "5.20"
assert cell(table, 1, 7).text_content().strip() == "s"
assert cell(table, 1, 10).text_content().replace(" ", "").strip() == " -/\n-/\n-ms".strip()
# Network I/O
assert cell(table, 7, 1).text_content().strip() == "Network I/O"
assert cell(table, 7, 6).text_content().strip() == "0.07"
assert cell(table, 7, 6).inner_html().strip() == '<span title="71208 Bytes/s">0.07</span>'
assert cell(table, 7, 7).text_content().strip() == "MB/s"
assert cell(table, 7, 4).text_content().strip() == "gcb-alpine-stress"
# Network Traffic
assert cell(table, 9, 1).text_content().strip() == "Network Traffic"
assert cell(table, 9, 4).text_content().strip() == "gcb-alpine-stress"
assert cell(table, 9, 6).text_content().strip() == "0.37"
assert cell(table, 9, 6).inner_html().strip() == '<span title="367908 Bytes">0.37</span>'
# Network Traffic
assert cell(table, 10, 1).text_content().strip() == "Network Traffic"
assert cell(table, 10, 4).text_content().strip() == "gcb-inserted-test"
assert cell(table, 10, 6).text_content().strip() == "0.04"
assert cell(table, 10, 6).inner_html().strip() == '<span title="41231 Bytes">0.04</span>'
# Machine Energy
assert cell(table, 11, 1).text_content().strip() == "Machine Energy"
assert cell(table, 11, 6).text_content().strip() == "21.14"
assert cell(table, 11, 7).text_content().strip() == "mWh"
assert cell(table, 11, 10).text_content().replace(" ", "").strip() == "99/\n100/\n101ms"
# Machine Power
assert cell(table, 12, 1).text_content().strip() == "Machine Power"
assert cell(table, 12, 6).text_content().strip() == "14.62"
assert cell(table, 12, 7).text_content().strip() == "W"
assert cell(table, 12, 10).text_content().replace(" ", "").strip() == "99/\n100/\n101ms"
# Network Transmission CO₂
assert cell(table, 15, 1).text_content().strip() == "Network Transmission CO₂"
assert cell(table, 15, 6).inner_html().strip() == (
'<span title="425 ug">0.00</span> '
'<span data-tooltip="Value is lower than rounding. Unrounded value is 425 ug" '
'data-position="bottom center" data-inverted=""><i class="question circle icon link"></i></span>'
)
assert cell(table, 15, 7).text_content().strip() == "g"
def test_stats_hidden_run(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
with context.expect_page() as new_page_info:
page.get_by_role("link", name="Hidden Phase Run").click()
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
new_page.wait_for_load_state("networkidle")
assert new_page.locator("#runtime-hidden-info").is_hidden() is False
assert new_page.locator("#run-failed").is_hidden() is True
assert new_page.locator("#run-warnings").is_hidden() is True
assert new_page.locator('#runtime-sub-phases > .item.runtime-step.hidden-phase-tab[data-tab="I am a hidden phase"]').inner_html() == '<i class="low vision icon"></i> <span class="hidden-phase-name hidden">I am a hidden phase</span>'
new_page.locator('#runtime-sub-phases > .item.runtime-step.hidden-phase-tab[data-tab="I am a hidden phase"]').click()
assert new_page.locator('#runtime-sub-phases > .item.runtime-step.hidden-phase-tab[data-tab="I am a hidden phase"]').inner_html() == '<i class="low vision icon"></i> <span class="hidden-phase-name">I am a hidden phase</span>'
assert new_page.locator('#runtime-hidden-info').is_hidden() is True # bc moved to other tab through click
def test_compare_with_hidden_phases(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
page.locator("#DataTables_Table_0 input[type=checkbox]").first.wait_for(timeout=5000) # wait for accordion to fetch XHR and display first checkboxes. otherwise query_selector_all might be empty
elements = page.query_selector_all("input[type=checkbox]")
elements[0].click()
elements[1].click()
with context.expect_page() as new_page_info:
page.locator('#compare-button').click() # will do usage-scenario-variables comparison
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
new_page.wait_for_load_state("networkidle")
assert new_page.locator('#runtime-hidden-info').is_hidden() is False # bc moved to other tab through click
assert new_page.locator('#runtime-sub-phases > .item.runtime-step.hidden-phase-tab[data-tab="I am a hidden phase"]').inner_html() == '<i class="low vision icon"></i> <span class="hidden-phase-name hidden">I am a hidden phase</span>'
new_page.locator('#runtime-sub-phases > .item.runtime-step.hidden-phase-tab[data-tab="I am a hidden phase"]').click()
assert new_page.locator('#runtime-sub-phases > .item.runtime-step.hidden-phase-tab[data-tab="I am a hidden phase"]').inner_html() == '<i class="low vision icon"></i> <span class="hidden-phase-name">I am a hidden phase</span>'
assert new_page.locator('#runtime-hidden-info').is_hidden() is True # bc moved to other tab through click
def test_stats_custom_metric_sci(self):
run_id = insert_demo_run_with_custom_sci_phase_stats()
stats_url = f"{GlobalConfig().config['cluster']['metrics_url']}/stats.html?id={run_id}"
page.goto(stats_url)
page.wait_for_load_state("networkidle")
page.locator('a.step[data-tab="[RUNTIME]"]').click()
page.locator('#runtime-steps phase-metrics .ui.accordion .title > a').first.click()
sci_card = page.locator('div.green.card.custom-metric-custom_hits_sci_global')
assert sci_card.locator('.metric-name').text_content() == 'Hits (SCI)'
assert sci_card.locator('.value.bold').text_content().strip() == '0.12'
assert sci_card.locator('.si-unit').text_content().strip() == 'gCO2e/Hits'
assert sci_card.locator('.source').text_content().strip() == 'via User supplied'
sci_table_row = page.locator('table.compare-metrics-table tbody tr', has_text='Hits (SCI)').first
assert sci_table_row.locator('td:nth-child(6)').text_content().strip() == '0.12'
assert sci_table_row.locator('td:nth-child(7)').text_content().strip() == 'gCO2e/Hits'
def test_stats_component_carbon(self):
# Verifies that operational carbon values are shown in the frontend not only for the
# machine, but for the individual energy components (CPU, DRAM, ...) as well.
run_id = insert_demo_run_with_component_carbon_phase_stats()
stats_url = f"{GlobalConfig().config['cluster']['metrics_url']}/stats.html?id={run_id}"
page.goto(stats_url)
page.wait_for_load_state("networkidle")
page.locator('a.step[data-tab="[RUNTIME]"]').click()
page.locator('#runtime-steps phase-metrics .ui.accordion .title > a').first.click()
# active runtime sub-phase ("Hit Generator") segment
runtime_segment = '#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics'
# CO₂ key-metric cards
cpu_co2_card = page.locator(f'{runtime_segment} div.ui.tab[data-tab="co2"] div.ui.black.card.cpu-co2')
assert cpu_co2_card.locator('.metric-name').text_content().strip() == 'CPU Package CO₂ (operational)'
assert cpu_co2_card.locator('.value.bold').text_content().strip() == '2.50'
assert cpu_co2_card.locator('.si-unit').text_content().strip() == 'gCO2e'
assert cpu_co2_card.locator('.source').text_content().strip() == 'via Formula (RAPL)'
dram_co2_card = page.locator(f'{runtime_segment} div.ui.tab[data-tab="co2"] div.ui.black.card.dram-co2')
assert dram_co2_card.locator('.metric-name').text_content().strip() == 'DRAM CO₂ (operational)'
assert dram_co2_card.locator('.value.bold').text_content().strip() == '1.50'
assert dram_co2_card.locator('.si-unit').text_content().strip() == 'gCO2e'
assert dram_co2_card.locator('.source').text_content().strip() == 'via RAPL'
# detailed metrics table rows
table = page.locator(f'{runtime_segment} table.compare-metrics-table')
cpu_row = table.locator('tbody tr', has_text='CPU Package CO₂ (operational)').first
assert cpu_row.locator('td:nth-child(6)').text_content().strip() == '2.50'
assert cpu_row.locator('td:nth-child(7)').text_content().strip() == 'gCO2e'
dram_row = table.locator('tbody tr', has_text='DRAM CO₂ (operational)').first
assert dram_row.locator('td:nth-child(6)').text_content().strip() == '1.50'
assert dram_row.locator('td:nth-child(7)').text_content().strip() == 'gCO2e'
def test_repositories_and_compare_with_diff(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
page.locator("#DataTables_Table_0 input[type=checkbox]").first.wait_for(timeout=5000) # wait for accordion to fetch XHR and display first checkboxes. otherwise query_selector_all might be empty
elements = page.query_selector_all("input[type=checkbox]")
elements[1].click()
elements[6].click()
with context.expect_page() as new_page_info:
page.locator('#compare-button').click() # will do usage-scenario-variables comparison
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
new_page.locator('#runtime-steps phase-metrics .ui.accordion .title > a').first.click()
# compare key metrics
machine_energy_value = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.tab[data-tab="energy"] div.ui.blue.card.machine-energy > div.extra.content span.value.bold').text_content()
phase_duration = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.runtime > div.extra.content span.value.bold').text_content()
cpu_package_power = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.tab[data-tab="power"] div.ui.orange.card.cpu-power > div.extra.content span.value.bold').text_content()
embodied_carbon = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.embodied-carbon > div.extra.content span.value.bold').text_content()
network_traffic = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.network-traffic > div.extra.content span.value.bold').text_content()
network_data = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.network-data > div.extra.content span.value.bold').text_content()
assert machine_energy_value.strip() == '+ 8.19 %'
assert phase_duration.strip() == '+ 4.80 %'
assert cpu_package_power.strip() == '+ 4.99 %'
assert embodied_carbon.strip() == '+ 4.80 %'
assert network_traffic.strip() == 'Not comparable ()'
assert network_data.strip() == 'Not comparable ()'
table = new_page.locator(
"#runtime-steps > div.ui.bottom.attached.active.tab.segment "
"> div.ui.segment.secondary > phase-metrics "
"> div.ui.accordion > div.content.active > table > tbody"
)
# --- Phase Duration (row 1) ---
first_metric = cell(table, 1, 1)
assert first_metric.text_content().strip() == "Phase Duration"
assert first_metric.inner_html().strip() == '<i class="question circle icon"></i>Phase Duration'
first_value = cell(table, 1, 6)
assert first_value.text_content().strip() == "5.06"
assert first_value.inner_html().strip() == '<span title="5064843 us">5.06</span>'
assert cell(table, 1, 8).inner_html().strip() == "s"
assert cell(table, 1, 9).inner_html().strip() == "+ 4.80 %"
# --- Network Traffic (row 9) ---
assert cell(table, 9, 1).text_content().strip() == "Network Traffic"
assert cell(table, 9, 4).text_content().strip() == "gcb-alpine-stress"
assert cell(table, 9, 6).text_content().strip() == "0.35"
assert cell(table, 9, 7).text_content().strip() == "0.39"
assert cell(table, 9, 8).text_content().strip() == "MB"
assert cell(table, 9, 9).text_content().strip() == "+ 8.94 %"
# --- Network Traffic (row 10) ---
assert cell(table, 10, 1).text_content().strip() == "Network Traffic"
assert cell(table, 10, 4).text_content().strip() == "gcb-inserted-test"
assert cell(table, 10, 6).text_content().strip() == "0.04"
assert cell(table, 10, 7).text_content().strip() == "undefined"
assert cell(table, 10, 8).text_content().strip() == "MB"
assert cell(table, 10, 9).text_content().strip() == "not comparable %"
# --- Machine Energy (row 11) ---
assert cell(table, 11, 1).text_content().strip() == "Machine Energy"
assert cell(table, 11, 6).text_content().strip() == "20.16"
assert cell(table, 11, 7).text_content().strip() == "21.81"
assert cell(table, 11, 8).text_content().strip() == "mWh"
assert cell(table, 11, 9).text_content().strip() == "+ 8.19 %"
# --- Network Transmission CO₂ (row 15) ---
assert cell(table, 15, 1).text_content().strip() == "Network Transmission CO₂"
assert cell(table, 15, 6).inner_html().strip() == (
'<span title="409 ug">0.00</span> '
'<span data-tooltip="Value is lower than rounding. Unrounded value is 409 ug" '
'data-position="bottom center" data-inverted=""><i class="question circle icon link"></i></span>'
)
assert cell(table, 15, 7).inner_html().strip() == (
'<span title="446 ug">0.00</span> '
'<span data-tooltip="Value is lower than rounding. Unrounded value is 446 ug" '
'data-position="bottom center" data-inverted=""><i class="question circle icon link"></i></span>'
)
assert cell(table, 15, 8).inner_html().strip() == "g"
assert cell(table, 15, 9).inner_html().strip() == "+ 9.05 %"
def test_repositories_compare_not_comparable_on_aggregate(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
page.locator("#DataTables_Table_0 input[type=checkbox]").first.wait_for(timeout=5000) # wait for accordion to fetch XHR and display first checkboxes. otherwise query_selector_all might be empty
elements = page.query_selector_all("input[type=checkbox]")
elements[6].click()
elements[7].click()
with context.expect_page() as new_page_info:
page.locator('#compare-button').click() # will do usage-scenario-variables comparison
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
new_page.locator('#runtime-steps phase-metrics .ui.accordion .title > a').first.click()
# compare key metrics
machine_energy_value = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.tab[data-tab="energy"] div.ui.blue.card.machine-energy > div.extra.content span.value.bold').text_content()
network_traffic = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.network-traffic > div.extra.content span.value.bold').inner_html()
network_data = new_page.locator('#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.segment div.ui.teal.card.network-data > div.extra.content span.value.bold').inner_html()
assert machine_energy_value.strip() == '-4.62 %'
assert network_traffic == 'Not comparable (<i class="window restore outline icon" title="This is an aggregate value based on multiple sources. Please check metrics table for individual values."></i>)'
assert network_data == 'Not comparable (<i class="window restore outline icon" title="This is an aggregate value based on multiple sources. Please check metrics table for individual values."></i>)'
def test_repositories_and_compare_repeated_run(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
page.get_by_role("button", name="Switch to repository view").click()
page.get_by_text("/home/arne/Sites/green-coding/example-applications/").click()
page.locator("#DataTables_Table_0 input[type=checkbox]").first.wait_for(timeout=5000) # wait for accordion to fetch XHR and display first checkboxes. otherwise query_selector_all might be empty
elements = page.query_selector_all("input[type=checkbox]")
elements[0].click()
elements[1].click()
elements[2].click()
with context.expect_page() as new_page_info:
page.locator('#compare-button').click()
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
comparison_type = new_page.locator('#run-data-top > tbody:nth-child(1) > tr > td:nth-child(2)').text_content()
assert comparison_type == 'Repeated Run on same Commit Hash'
runs_compared = new_page.locator('#run-data-top > tbody:nth-child(2) > tr > td:nth-child(2)').text_content()
assert runs_compared == '3'
# open details
new_page.locator('a.step[data-tab="[RUNTIME]"]').click()
new_page.locator('#runtime-steps phase-metrics .ui.accordion .title > a').first.click()
first_metric = new_page.locator("#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(3) > td:nth-child(1)").text_content()
assert first_metric.strip() == 'CPU Package Power'
first_type = new_page.locator("#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(3) > td:nth-child(5)")
assert first_type.text_content().strip() == 'MEAN'
first_value = new_page.locator("#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(3) > td:nth-child(6)")
assert first_value.text_content().strip() == '8.64'
assert first_value.inner_html().strip() == '<span title="8637 mW">8.64</span>'
first_unit = new_page.locator("#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(3) > td:nth-child(7)").text_content()
assert first_unit.strip() == 'W'
first_stddev = new_page.locator("#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(3) > td:nth-child(8)").text_content()
assert first_stddev.strip() == '± 2.85%'
assert new_page.locator("#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(13) > td:nth-child(6)").inner_html() == '<span title="435.5 ug">0.00</span> <span data-tooltip="Value is lower than rounding. Unrounded value is 435.5 ug" data-position="bottom center" data-inverted=""><i class="question circle icon link"></i></span>'
assert new_page.locator("#runtime-steps > div.ui.bottom.attached.active.tab.segment > div.ui.segment.secondary > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(13) > td:nth-child(8)").inner_html() == '± 3.41%'
# click on baseline
new_page.locator('a.step[data-tab="[BASELINE]"]').click()
new_page.locator('div[data-tab="[BASELINE]"] .ui.accordion a').click()
first_metric = new_page.locator("#main > div.ui.tab.attached.segment.secondary.active > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(2) > td:nth-child(1)").text_content()
assert first_metric.strip() == 'CPU Package Energy'
first_value = new_page.locator("#main > div.ui.tab.attached.segment.secondary.active > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(2) > td:nth-child(6)").text_content()
assert first_value.strip() == '2.62'
first_unit = new_page.locator("#main > div.ui.tab.attached.segment.secondary.active > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(2) > td:nth-child(7)").text_content()
assert first_unit.strip() == 'mWh'
first_stddev = new_page.locator("#main > div.ui.tab.attached.segment.secondary.active > phase-metrics > div.ui.accordion > div.content.active > table > tbody > tr:nth-child(2) > td:nth-child(8)").text_content()
assert first_stddev.strip() == '± 3.89%'
new_page.close()
def test_expert_compare_mode(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.wait_for_load_state("load") # wait JS
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
page.locator("#DataTables_Table_0 input[type=checkbox]").first.wait_for(timeout=5000) # wait for accordion to fetch XHR and display first checkboxes. otherwise query_selector_all might be empty
elements = page.query_selector_all("input[type=checkbox]")
elements[1].click()
elements[2].click()
elements[3].click()
elements[5].click()
with context.expect_page() as new_page_info:
page.locator('#compare-button').click()
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
assert new_page.locator("#run-data-top > tbody:first-child > tr:first-child > td:nth-child(2)").text_content() == 'Usage Scenario'
new_page.close()
page.locator('#unselect-button').click()
elements = page.query_selector_all("input[type=checkbox]")
elements[1].click()
elements[2].click()
elements[3].click()
elements[5].click()
page.locator('#compare-force-mode').select_option("Machines")
with context.expect_page() as new_page_info:
page.locator('#compare-button').click()
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
assert new_page.locator("#run-data-top > tbody:first-child > tr > td:nth-child(2)").text_content() == 'Machine'
assert new_page.locator("#run-data-top > tbody:nth-child(2) > tr > td:first-child").text_content() == 'Number of runs compared'
assert new_page.locator("#run-data-top > tbody:nth-child(2) > tr > td:nth-child(2)").text_content() == '4'
assert new_page.locator("#run-data-top > tbody:nth-child(3) > tr > td:nth-child(1)").text_content() == 'Machine'
assert new_page.locator("#run-data-top > tbody:nth-child(3) > tr > td:nth-child(2)").text_content() == 'Development machine for testing'
new_page.close()
def test_new_usage_scenario_variables_compare_mode(self):
page.goto(GlobalConfig().config['cluster']['metrics_url'] + '/index.html')
page.locator("#menu").get_by_role("link", name="Runs / Repos", exact=True).click()
page.locator("#DataTables_Table_0 input[type=checkbox]").first.wait_for(timeout=5000) # wait for accordion to fetch XHR and display first checkboxes. otherwise query_selector_all might be empty
elements = page.query_selector_all("input[type=checkbox]")
elements[0].click()
elements[1].click()
elements[2].click()
elements[3].click()
elements[4].click()
elements[5].click()
page.locator('#compare-force-mode').select_option('Variables')
with context.expect_page() as new_page_info:
page.locator('#compare-button').click()
new_page = new_page_info.value
new_page.set_default_timeout(3_000)
assert new_page.locator("#run-data-top > tbody:first-child > tr:first-child > td:nth-child(2)").text_content() == 'Usage Scenario Variables'
assert new_page.locator("#run-data-top > tbody:nth-child(2) > tr > td:first-child").text_content() == 'Number of runs compared'
assert new_page.locator("#run-data-top > tbody:nth-child(2) > tr > td:nth-child(2)").text_content() == '6'
table_cell = new_page.locator("#run-data-top > tbody:nth-child(3) > tr > td:nth-child(2)")
assert "Variable" in table_cell.text_content() # Should contain table header
assert "__GMT_VAR_STATUS__" in table_cell.text_content() # Should contain the variable name
assert "I love the GMT!" in table_cell.text_content() # Should contain the value
new_page.close()
def test_stats_commit_hash_display(self):
"""Verify commit_hash renders as link for HTTPS/SSH URIs, plain text for local paths."""
github_run_id = str(uuid.uuid4())
github_ssh_run_id = str(uuid.uuid4())
github_dotgit_run_id = str(uuid.uuid4())
gitlab_run_id = str(uuid.uuid4())
gitlab_ssh_run_id = str(uuid.uuid4())
bitbucket_run_id = str(uuid.uuid4())
local_run_id = str(uuid.uuid4())
base_insert = """
INSERT INTO runs (id, name, uri, branch, commit_hash, usage_scenario, filename, machine_id, user_id, failed, logs, created_at, updated_at)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW())
"""
empty_scenario = json.dumps({"name": "test", "flow": []})
commit_hash = 'aabbccddee0011223344'
DB().query(base_insert, params=(
github_run_id, 'GitHub HTTPS',
'https://github.com/org/demo-repo', 'main',
commit_hash, empty_scenario, 'test.yml', 1, 1, False, '{}'
))
DB().query(base_insert, params=(
github_ssh_run_id, 'GitHub SSH',
'git@github.com:org/demo-repo.git', 'main',
commit_hash, empty_scenario, 'test.yml', 1, 1, False, '{}'
))
DB().query(base_insert, params=(
github_dotgit_run_id, 'GitHub HTTPS .git',
'https://github.com/org/demo-repo.git', 'main',
commit_hash, empty_scenario, 'test.yml', 1, 1, False, '{}'
))
DB().query(base_insert, params=(
gitlab_run_id, 'GitLab HTTPS',
'https://gitlab.com/org/demo-repo', 'main',
commit_hash, empty_scenario, 'test.yml', 1, 1, False, '{}'
))
DB().query(base_insert, params=(
gitlab_ssh_run_id, 'GitLab SSH',
'git@gitlab.com:org/demo-repo.git', 'main',
commit_hash, empty_scenario, 'test.yml', 1, 1, False, '{}'
))
DB().query(base_insert, params=(
bitbucket_run_id, 'Bitbucket HTTPS',
'https://bitbucket.org/org/demo-repo', 'main',
commit_hash, empty_scenario, 'test.yml', 1, 1, False, '{}'
))