• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MinaProtocol / mina / 2863

05 Nov 2024 06:20PM UTC coverage: 30.754% (-16.6%) from 47.311%
2863

push

buildkite

web-flow
Merge pull request #16296 from MinaProtocol/dkijania/more_multi_jobs

more multi jobs in CI

20276 of 65930 relevant lines covered (30.75%)

8631.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.29
/src/lib/work_selector/random_offset.ml
1
open Core_kernel
1✔
2

3
(** The work selection method implemented here is the following. We distinguish
4
two cases:
5
    1. The work pool is updated: a random [offset] is generated. The selected
6
    work is the [offset]-th one of the expensive work list.
7
    2. As long as the pool stays the same, the works are selected sequentially
8
    from the offset. If the end of the work list is reached, the next works are
9
    selected sequentially from the beginning of the list. *)
10
module Make
11
    (Inputs : Intf.Inputs_intf)
12
    (Lib : Intf.Lib_intf with module Inputs := Inputs) =
13
struct
14
  module Offset = struct
15
    (* The initialization for the first offset can be 0; as the first
16
       [previous_length] 0, any non-empty list will trigger an update of the offset. *)
17
    let offset = ref 0
18

19
    (* The previous length of expensive works [work] got through *)
20
    let prev_length = ref 0
21

22
    (* This function maintains [prev_length] & [offset] up do date.
23
       When the pool is not updated, we consider that its length should
24
       decrease by 1 ([new_length = !prev_length - 1]). If an other behavior
25
       is observed, the pool is considered updated and a new [offset] is
26
       generated randomly, uniformly chosen between 0 and [new_length]. *)
27
    let update ~new_length =
28
      let () =
×
29
        if new_length = !prev_length - 1 then ()
×
30
        else offset := Random.int new_length
×
31
      in
32
      prev_length := new_length
33

34
    (* Because of the [offset] being constant and the [expensive_work] list
35
       reducing in size, a case where [offset] ends up greater than the list
36
       length may happen. In that case, we go back to the beginning of the list,
37
       by resetting [offset] to 0.
38
       /!\ fails if [expensive_work] is empty! *)
39
    let get_nth expensive_work =
40
      try List.nth_exn expensive_work !offset
×
41
      with _ ->
×
42
        (* Raising an error here means that offset is now too large for the
43
           list -> back to the beginning with offset at 0 *)
44
        offset := 0 ;
45
        List.nth_exn expensive_work !offset
46
  end
47

48
  let work ~snark_pool ~fee ~logger (state : Lib.State.t) =
49
    Lib.State.remove_old_assignments state ~logger ;
×
50
    let unseen_jobs = Lib.State.all_unseen_works state in
×
51
    match Lib.get_expensive_work ~snark_pool ~fee unseen_jobs with
×
52
    | [] ->
×
53
        None
54
    | expensive_work ->
×
55
        Offset.update ~new_length:(List.length expensive_work) ;
×
56
        let x = Offset.get_nth expensive_work in
57
        Lib.State.set state x ; Some x
×
58

59
  let remove = Lib.State.remove
60

61
  let pending_work_statements = Lib.pending_work_statements
62
end
63

64
let%test_module "test" =
65
  ( module struct
66
    module Test = Test.Make_test (Make)
67
  end )
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc