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

MinaProtocol / mina / 2841

30 Oct 2024 07:56AM UTC coverage: 33.412% (-27.7%) from 61.098%
2841

push

buildkite

web-flow
Merge pull request #16306 from MinaProtocol/dkijania/fix_promotion_to_gcr

Fix promotion job PUBLISH misuse

22273 of 66661 relevant lines covered (33.41%)

119594.1 hits per line

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

36.36
/src/lib/timeout_lib/timeout_lib.ml
1
open Async_kernel
10✔
2
open Core_kernel
3

4
module type Time_intf = sig
5
  type t
6

7
  module Span : sig
8
    type t
9

10
    val to_time_ns_span : t -> Time_ns.Span.t
11

12
    val ( - ) : t -> t -> t
13
  end
14

15
  module Controller : sig
16
    type t
17
  end
18

19
  val now : Controller.t -> t
20

21
  val diff : t -> t -> Span.t
22
end
23

24
module Timeout_intf (Time : Time_intf) = struct
25
  module type S = sig
26
    type 'a t
27

28
    val create : Time.Controller.t -> Time.Span.t -> f:(Time.t -> 'a) -> 'a t
29

30
    val to_deferred : 'a t -> 'a Async_kernel.Deferred.t
31

32
    val peek : 'a t -> 'a option
33

34
    val cancel : Time.Controller.t -> 'a t -> 'a -> unit
35

36
    val remaining_time : 'a t -> Time.Span.t
37

38
    val await :
39
         timeout_duration:Time.Span.t
40
      -> Time.Controller.t
41
      -> 'a Deferred.t
42
      -> [ `Ok of 'a | `Timeout ] Deferred.t
43

44
    val await_exn :
45
         timeout_duration:Time.Span.t
46
      -> Time.Controller.t
47
      -> 'a Deferred.t
48
      -> 'a Deferred.t
49
  end
50
end
51

52
module Make (Time : Time_intf) : Timeout_intf(Time).S = struct
53
  type 'a t =
54
    { deferred : 'a Deferred.t
55
    ; cancel : 'a -> unit
56
    ; start_time : Time.t
57
    ; span : Time.Span.t
58
    ; ctrl : Time.Controller.t
59
    }
60

61
  let create ctrl span ~f:action =
62
    let open Deferred.Let_syntax in
6✔
63
    let cancel_ivar = Ivar.create () in
64
    let timeout = after (Time.Span.to_time_ns_span span) >>| fun () -> None in
×
65
    let deferred =
6✔
66
      Deferred.any [ Ivar.read cancel_ivar; timeout ]
6✔
67
      >>| function None -> action (Time.now ctrl) | Some x -> x
×
68
    in
69
    let cancel value = Ivar.fill_if_empty cancel_ivar (Some value) in
×
70
    { ctrl; deferred; cancel; start_time = Time.now ctrl; span }
6✔
71

72
  let to_deferred { deferred; _ } = deferred
×
73

74
  let peek { deferred; _ } = Deferred.peek deferred
×
75

76
  let cancel _ { cancel; _ } value = cancel value
×
77

78
  let remaining_time { ctrl : _; start_time; span; _ } =
79
    let current_time = Time.now ctrl in
×
80
    let time_elapsed = Time.diff current_time start_time in
×
81
    Time.Span.(span - time_elapsed)
×
82

83
  let await ~timeout_duration time_controller deferred =
84
    let timeout =
6✔
85
      Deferred.create (fun ivar ->
86
          ignore
6✔
87
            ( create time_controller timeout_duration ~f:(fun x ->
6✔
88
                  if Ivar.is_full ivar then
×
89
                    [%log' error (Logger.create ())] "Ivar.fill bug is here!" ;
×
90
                  Ivar.fill_if_empty ivar x )
×
91
              : unit t ) )
92
    in
93
    Deferred.(
6✔
94
      choose
95
        [ choice deferred (fun x -> `Ok x); choice timeout (Fn.const `Timeout) ])
6✔
96

97
  let await_exn ~timeout_duration time_controller deferred =
98
    match%map await ~timeout_duration time_controller deferred with
×
99
    | `Timeout ->
×
100
        failwith "timeout"
101
    | `Ok x ->
×
102
        x
103
end
104

105
module Core_time = Make (struct
106
  include (
107
    Core_kernel.Time :
108
      module type of Core_kernel.Time
109
        with module Span := Core_kernel.Time.Span
110
         and type underlying = float )
111

112
  module Controller = struct
113
    type t = unit
114
  end
115

116
  module Span = struct
117
    include Core_kernel.Time.Span
118

119
    let to_time_ns_span = Fn.compose Core_kernel.Time_ns.Span.of_ns to_ns
10✔
120
  end
121

122
  let diff x y =
123
    let x_ns = Span.to_ns @@ to_span_since_epoch x in
×
124
    let y_ns = Span.to_ms @@ to_span_since_epoch y in
×
125
    Span.of_ns (x_ns -. y_ns)
×
126
end)
127

128
module Core_time_ns = Make (struct
129
  include (
130
    Core_kernel.Time_ns :
131
      module type of Core_kernel.Time_ns
132
        with module Span := Core_kernel.Time_ns.Span )
133

134
  module Controller = struct
135
    type t = unit
136
  end
137

138
  module Span = struct
139
    include Core_kernel.Time_ns.Span
140

141
    let to_time_ns_span = Fn.id
142
  end
143

144
  let diff x y =
145
    let x_ns = Span.to_ns @@ to_span_since_epoch x in
×
146
    let y_ns = Span.to_ms @@ to_span_since_epoch y in
×
147
    Span.of_ns (x_ns -. y_ns)
×
148
end)
20✔
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