|
1 "use strict"; |
|
2 |
|
3 let {OS: {File, Path, Constants}} = Components.utils.import("resource://gre/modules/osfile.jsm", {}); |
|
4 let {Services} = Components.utils.import("resource://gre/modules/Services.jsm", {}); |
|
5 |
|
6 // Ensure that we have a profile but that the OS.File worker is not launched |
|
7 add_task(function* init() { |
|
8 do_get_profile(); |
|
9 yield File.resetWorker(); |
|
10 }); |
|
11 |
|
12 function getCount(histogram) { |
|
13 if (histogram == null) { |
|
14 return 0; |
|
15 } |
|
16 |
|
17 let total = 0; |
|
18 for (let i of histogram.counts) { |
|
19 total += i; |
|
20 } |
|
21 return total; |
|
22 } |
|
23 |
|
24 // Ensure that launching the OS.File worker adds data to the relevant |
|
25 // histograms |
|
26 add_task(function* test_startup() { |
|
27 let LAUNCH = "OSFILE_WORKER_LAUNCH_MS"; |
|
28 let READY = "OSFILE_WORKER_READY_MS"; |
|
29 |
|
30 let before = Services.telemetry.histogramSnapshots; |
|
31 |
|
32 // Launch the OS.File worker |
|
33 yield File.getCurrentDirectory(); |
|
34 |
|
35 let after = Services.telemetry.histogramSnapshots; |
|
36 |
|
37 |
|
38 do_print("Ensuring that we have recorded measures for histograms"); |
|
39 do_check_eq(getCount(after[LAUNCH]), getCount(before[LAUNCH]) + 1); |
|
40 do_check_eq(getCount(after[READY]), getCount(before[READY]) + 1); |
|
41 |
|
42 do_print("Ensuring that launh <= ready"); |
|
43 do_check_true(after[LAUNCH].sum <= after[READY].sum); |
|
44 }); |
|
45 |
|
46 // Ensure that calling writeAtomic adds data to the relevant histograms |
|
47 add_task(function* test_writeAtomic() { |
|
48 let LABEL = "OSFILE_WRITEATOMIC_JANK_MS"; |
|
49 |
|
50 let before = Services.telemetry.histogramSnapshots; |
|
51 |
|
52 // Perform a write. |
|
53 let path = Path.join(Constants.Path.profileDir, "test_osfile_telemetry.tmp"); |
|
54 yield File.writeAtomic(path, LABEL, { tmpPath: path + ".tmp" } ); |
|
55 |
|
56 let after = Services.telemetry.histogramSnapshots; |
|
57 |
|
58 do_check_eq(getCount(after[LABEL]), getCount(before[LABEL]) + 1); |
|
59 }); |
|
60 |
|
61 function run_test() { |
|
62 run_next_test(); |
|
63 } |