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
use std::cell::RefCell;
use std::collections::HashMap;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::marker::PhantomData;
use std::rc::Rc;
use std::time::Duration;
use itertools::Itertools;
use rtlola_frontend::mir::{InputReference, OutputReference, RtLolaMir, Type};
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::config::Config;
use crate::configuration::time::{init_start_time, OutputTimeRepresentation, RelativeFloat, TimeRepresentation};
use crate::evaluator::{Evaluator, EvaluatorData};
use crate::schedule::schedule_manager::ScheduleManager;
use crate::schedule::DynamicSchedule;
use crate::storage::Value;
use crate::{CondDeserialize, CondSerialize, NoError, Time};
pub type Event = Vec<Value>;
pub trait VerdictRepresentation: Clone + Debug + Send + CondSerialize + 'static {
type Tracing: Tracer;
fn create(data: RawVerdict) -> Self;
fn create_with_trace(data: RawVerdict, _tracing: Self::Tracing) -> Self {
Self::create(data)
}
fn is_empty(&self) -> bool;
}
pub trait Tracer: Default + Clone + Debug + Send + CondSerialize + 'static {
fn parse_start(&mut self) {}
fn parse_end(&mut self) {}
fn eval_start(&mut self) {}
fn eval_end(&mut self) {}
fn spawn_start(&mut self, _output: OutputReference) {}
fn spawn_end(&mut self, _output: OutputReference) {}
fn instance_eval_start(&mut self, _output: OutputReference, _instance: &[Value]) {}
fn instance_eval_end(&mut self, _output: OutputReference, _instance: &[Value]) {}
fn close_start(&mut self, _output: OutputReference, _instance: &[Value]) {}
fn close_end(&mut self, _output: OutputReference, _instance: &[Value]) {}
}
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(Debug, Clone, Copy, Default)]
pub struct NoTracer {}
impl Tracer for NoTracer {}
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(Debug, Clone)]
pub struct TracingVerdict<T: Tracer, V: VerdictRepresentation> {
pub tracer: T,
pub verdict: V,
}
impl<T: Tracer, V: VerdictRepresentation<Tracing = NoTracer>> VerdictRepresentation for TracingVerdict<T, V> {
type Tracing = T;
fn create(data: RawVerdict) -> Self {
Self {
tracer: T::default(),
verdict: V::create(data),
}
}
fn create_with_trace(data: RawVerdict, tracing: Self::Tracing) -> Self {
Self {
tracer: tracing,
verdict: V::create(data),
}
}
fn is_empty(&self) -> bool {
V::is_empty(&self.verdict)
}
}
pub type Parameters = Option<Vec<Value>>;
pub type Instance = (Parameters, Option<Value>);
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub enum Change {
Spawn(Vec<Value>),
Value(Parameters, Value),
Close(Vec<Value>),
}
impl Display for Change {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Change::Spawn(para) => write!(f, "Spawn<{}>", para.iter().join(", ")),
Change::Close(para) => write!(f, "Close<{}>", para.iter().join(", ")),
Change::Value(para, value) => {
match para {
Some(para) => write!(f, "Instance<{}> = {}", para.iter().join(", "), value),
None => write!(f, "Value = {}", value),
}
},
}
}
}
pub type Incremental = Vec<(OutputReference, Vec<Change>)>;
impl VerdictRepresentation for Incremental {
type Tracing = NoTracer;
fn create(data: RawVerdict) -> Self {
data.eval
.peek_fresh_outputs()
.into_iter()
.chain(
data.eval
.peek_violated_triggers()
.into_iter()
.map(|t| (t, vec![Change::Value(None, Value::Bool(true))])),
)
.collect()
}
fn is_empty(&self) -> bool {
Vec::is_empty(self)
}
}
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(Debug, Clone)]
pub struct TotalIncremental {
pub inputs: Vec<(InputReference, Value)>,
pub outputs: Vec<(OutputReference, Vec<Change>)>,
pub trigger: Vec<(OutputReference, String)>,
}
impl VerdictRepresentation for TotalIncremental {
type Tracing = NoTracer;
fn create(data: RawVerdict) -> Self {
let inputs = data.eval.peek_fresh_input();
let outputs = data.eval.peek_fresh_outputs();
let trigger = data
.eval
.peek_violated_triggers()
.into_iter()
.map(|t| (t, data.eval.format_trigger_message(t)))
.collect();
Self {
inputs,
outputs,
trigger,
}
}
fn is_empty(&self) -> bool {
self.inputs.is_empty() && self.outputs.is_empty() && self.trigger.is_empty()
}
}
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Total {
pub inputs: Vec<Option<Value>>,
pub outputs: Vec<Vec<Instance>>,
}
impl VerdictRepresentation for Total {
type Tracing = NoTracer;
fn create(data: RawVerdict) -> Self {
Total {
inputs: data.eval.peek_inputs(),
outputs: data.eval.peek_outputs(),
}
}
fn is_empty(&self) -> bool {
false
}
}
pub type TriggerMessages = Vec<(OutputReference, String)>;
impl VerdictRepresentation for TriggerMessages {
type Tracing = NoTracer;
fn create(data: RawVerdict) -> Self
where
Self: Sized,
{
let violated_trigger = data.eval.peek_violated_triggers();
violated_trigger
.into_iter()
.map(|sr| (sr, data.eval.format_trigger_message(sr)))
.collect()
}
fn is_empty(&self) -> bool {
Vec::is_empty(self)
}
}
pub type TriggersWithInfoValues = Vec<(OutputReference, Vec<Option<Value>>)>;
impl VerdictRepresentation for TriggersWithInfoValues {
type Tracing = NoTracer;
fn create(data: RawVerdict) -> Self
where
Self: Sized,
{
let violated_trigger = data.eval.peek_violated_triggers();
violated_trigger
.into_iter()
.map(|sr| (sr, data.eval.peek_info_stream_values(sr)))
.collect()
}
fn is_empty(&self) -> bool {
Vec::is_empty(self)
}
}
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(Debug, Clone)]
pub struct Verdicts<V: VerdictRepresentation, VerdictTime: OutputTimeRepresentation> {
pub timed: Vec<(VerdictTime::InnerTime, V)>,
pub event: V,
pub ts: VerdictTime::InnerTime,
}
#[allow(missing_debug_implementations)]
pub struct Monitor<Source, SourceTime, Verdict = Incremental, VerdictTime = RelativeFloat>
where
Source: Input,
SourceTime: TimeRepresentation,
Verdict: VerdictRepresentation,
VerdictTime: OutputTimeRepresentation + 'static,
{
ir: RtLolaMir,
eval: Evaluator,
schedule_manager: ScheduleManager,
source: Source,
source_time: SourceTime,
output_time: VerdictTime,
phantom: PhantomData<Verdict>,
}
impl<Source, SourceTime, Verdict, VerdictTime> Monitor<Source, SourceTime, Verdict, VerdictTime>
where
Source: Input,
SourceTime: TimeRepresentation,
Verdict: VerdictRepresentation,
VerdictTime: OutputTimeRepresentation,
{
pub fn setup(
config: Config<SourceTime, VerdictTime>,
setup_data: Source::CreationData,
) -> Result<Monitor<Source, SourceTime, Verdict, VerdictTime>, Source::Error> {
let dyn_schedule = Rc::new(RefCell::new(DynamicSchedule::new()));
let source_time = config.input_time_representation;
let output_time = VerdictTime::default();
init_start_time::<SourceTime>(config.start_time);
let input_map = config
.ir
.inputs
.iter()
.map(|i| (i.name.clone(), i.reference.in_ix()))
.collect();
let eval_data = EvaluatorData::new(config.ir.clone(), dyn_schedule.clone());
let time_manager = ScheduleManager::setup(config.ir.clone(), dyn_schedule)
.expect("Error computing schedule for time-driven streams");
Ok(Monitor {
ir: config.ir,
eval: eval_data.into_evaluator(),
schedule_manager: time_manager,
source: Source::new(input_map, setup_data)?,
source_time,
output_time,
phantom: PhantomData,
})
}
fn eval_deadlines(&mut self, ts: Time, only_before: bool) -> Vec<(Time, Verdict)> {
let mut timed: Vec<(Time, Verdict)> = vec![];
while self.schedule_manager.get_next_due().is_some() {
let mut tracer = Verdict::Tracing::default();
tracer.eval_start();
let due = self.schedule_manager.get_next_due().unwrap();
if due > ts || (only_before && due == ts) {
break;
}
let deadline = self.schedule_manager.get_next_deadline(ts);
self.eval.eval_time_driven_tasks(deadline, due, &mut tracer);
tracer.eval_end();
timed.push((due, Verdict::create_with_trace(RawVerdict::from(&self.eval), tracer)))
}
timed
}
}
#[allow(missing_debug_implementations)]
#[derive(Copy, Clone)]
pub struct RawVerdict<'a> {
eval: &'a Evaluator,
}
impl<'a> From<&'a Evaluator> for RawVerdict<'a> {
fn from(eval: &'a Evaluator) -> Self {
RawVerdict { eval }
}
}
pub trait Input: Sized {
type Record: Send;
type Error: Error + Send + 'static;
type CreationData: Clone + Send;
fn new(map: HashMap<String, InputReference>, setup_data: Self::CreationData) -> Result<Self, Self::Error>;
fn get_event(&self, rec: Self::Record) -> Result<Event, Self::Error>;
}
pub trait Record: Send {
type CreationData: Clone + Send;
type Error: Error + Send + 'static;
fn func_for_input(name: &str, data: Self::CreationData) -> Result<ValueProjection<Self, Self::Error>, Self::Error>;
}
pub type ValueProjection<From, E> = Box<dyn (Fn(&From) -> Result<Value, E>)>;
#[allow(missing_debug_implementations)]
pub struct RecordInput<Inner: Record> {
translators: Vec<ValueProjection<Inner, Inner::Error>>,
}
impl<Inner: Record> Input for RecordInput<Inner> {
type CreationData = Inner::CreationData;
type Error = Inner::Error;
type Record = Inner;
fn new(map: HashMap<String, InputReference>, setup_data: Self::CreationData) -> Result<Self, Self::Error> {
let mut translators: Vec<Option<_>> = (0..map.len()).map(|_| None).collect();
for (input_name, index) in map {
translators[index] = Some(Inner::func_for_input(input_name.as_str(), setup_data.clone())?)
}
let translators = translators.into_iter().map(Option::unwrap).collect();
Ok(Self { translators })
}
fn get_event(&self, rec: Inner) -> Result<Event, Self::Error> {
self.translators.iter().map(|f| f(&rec)).collect()
}
}
#[derive(Debug, Clone)]
pub struct EventInput<E: Into<Event> + CondSerialize + CondDeserialize> {
phantom: PhantomData<E>,
}
impl<E: Into<Event> + Send + CondSerialize + CondDeserialize> Input for EventInput<E> {
type CreationData = ();
type Error = NoError;
type Record = E;
fn new(_map: HashMap<String, InputReference>, _setup_data: Self::CreationData) -> Result<Self, Self::Error> {
Ok(EventInput { phantom: PhantomData })
}
fn get_event(&self, rec: Self::Record) -> Result<Event, Self::Error> {
Ok(rec.into())
}
}
impl<Source, SourceTime, Verdict, VerdictTime> Monitor<Source, SourceTime, Verdict, VerdictTime>
where
Source: Input,
SourceTime: TimeRepresentation,
Verdict: VerdictRepresentation,
VerdictTime: OutputTimeRepresentation,
{
pub fn accept_event(
&mut self,
ev: Source::Record,
ts: SourceTime::InnerTime,
) -> Result<Verdicts<Verdict, VerdictTime>, Source::Error> {
let mut tracer = Verdict::Tracing::default();
tracer.parse_start();
let ev = self.source.get_event(ev)?;
tracer.parse_end();
let ts = self.source_time.convert_from(ts);
let timed = if self.ir.has_time_driven_features() {
self.eval_deadlines(ts, true)
} else {
vec![]
};
tracer.eval_start();
self.eval.eval_event(ev.as_slice(), ts, &mut tracer);
tracer.eval_end();
let event_change = Verdict::create_with_trace(RawVerdict::from(&self.eval), tracer);
let timed = timed
.into_iter()
.map(|(t, v)| (self.output_time.convert_into(t), v))
.collect();
Ok(Verdicts::<Verdict, VerdictTime> {
timed,
event: event_change,
ts: self.output_time.convert_into(ts),
})
}
pub fn accept_time(&mut self, ts: SourceTime::InnerTime) -> Vec<(VerdictTime::InnerTime, Verdict)> {
let ts = self.source_time.convert_from(ts);
let timed = if self.ir.has_time_driven_features() {
self.eval_deadlines(ts, false)
} else {
vec![]
};
timed
.into_iter()
.map(|(t, v)| (self.output_time.convert_into(t), v))
.collect()
}
pub fn ir(&self) -> &RtLolaMir {
&self.ir
}
pub fn name_for_input(&self, id: InputReference) -> &str {
self.ir.inputs[id].name.as_str()
}
pub fn name_for_output(&self, id: OutputReference) -> &str {
self.ir.outputs[id].name.as_str()
}
pub fn trigger_message(&self, id: usize) -> &str {
self.ir.triggers[id].message.as_str()
}
pub fn trigger_stream_index(&self, id: usize) -> usize {
self.ir.triggers[id].reference.out_ix()
}
pub fn number_of_input_streams(&self) -> usize {
self.ir.inputs.len()
}
pub fn number_of_output_streams(&self) -> usize {
self.ir.outputs.len()
}
pub fn number_of_triggers(&self) -> usize {
self.ir.triggers.len()
}
pub fn type_of_input(&self, id: InputReference) -> &Type {
&self.ir.inputs[id].ty
}
pub fn type_of_output(&self, id: OutputReference) -> &Type {
&self.ir.outputs[id].ty
}
pub fn extend_rate_of_output(&self, id: OutputReference) -> Option<Duration> {
self.ir
.time_driven
.iter()
.find(|time_driven_stream| time_driven_stream.reference.out_ix() == id)
.map(|time_driven_stream| time_driven_stream.period_in_duration())
}
pub fn with_verdict_representation<T: VerdictRepresentation>(self) -> Monitor<Source, SourceTime, T, VerdictTime> {
let Monitor {
ir,
eval,
schedule_manager: time_manager,
source_time,
source,
output_time,
phantom: _,
} = self;
Monitor {
ir,
eval,
schedule_manager: time_manager,
source_time,
source,
output_time,
phantom: PhantomData,
}
}
}
#[cfg(test)]
mod tests {
use std::time::{Duration, Instant};
use crate::api::monitor::Change;
use crate::monitor::{Event, EventInput, Incremental, Monitor, Total, Value, VerdictRepresentation};
use crate::time::RelativeFloat;
use crate::ConfigBuilder;
fn setup<V: VerdictRepresentation>(
spec: &str,
) -> (Instant, Monitor<EventInput<Event>, RelativeFloat, V, RelativeFloat>) {
let monitor = ConfigBuilder::new()
.spec_str(spec)
.offline::<RelativeFloat>()
.event_input::<Event>()
.with_verdict::<V>()
.monitor()
.expect("Failed to create monitor");
(Instant::now(), monitor)
}
fn sort_total(res: Total) -> Total {
let Total { inputs, mut outputs } = res;
outputs.iter_mut().for_each(|s| s.sort());
Total { inputs, outputs }
}
fn sort_incremental(mut res: Incremental) -> Incremental {
res.iter_mut().for_each(|(_, changes)| changes.sort());
res
}
#[test]
fn test_const_output_literals() {
let (start, mut monitor) = setup::<Total>(
r#"
input i_0: UInt8
output o_0: Bool @i_0 := true
output o_1: UInt8 @i_0 := 3
output o_2: Int8 @i_0 := -5
output o_3: Float32 @i_0 := -123.456
output o_4: String @i_0 := "foobar"
"#,
);
let v = Value::Unsigned(3);
let res = monitor
.accept_event(vec![v.clone()], start.elapsed())
.expect("Failed to accept value");
assert!(res.timed.is_empty());
let res = res.event;
assert_eq!(res.inputs[0], Some(v));
assert_eq!(res.outputs[0][0], (None, Some(Value::Bool(true))));
assert_eq!(res.outputs[1][0], (None, Some(Value::Unsigned(3))));
assert_eq!(res.outputs[2][0], (None, Some(Value::Signed(-5))));
assert_eq!(res.outputs[3][0], (None, Some(Value::new_float(-123.456))));
assert_eq!(res.outputs[4][0], (None, Some(Value::Str("foobar".into()))));
}
#[test]
fn test_count_window() {
let (_, mut monitor) =
setup::<Incremental>("input a: UInt16\noutput b: UInt16 @0.25Hz := a.aggregate(over: 40s, using: #)");
let n = 25;
let mut time = Duration::from_secs(45);
let res = monitor
.accept_event(vec![Value::Unsigned(1)], time)
.expect("Failed to accept value");
assert!(res.event.is_empty());
assert_eq!(res.timed.len(), 11);
assert!(res.timed.iter().all(|(time, change)| {
time.as_secs() % 4 == 0 && change[0].0 == 0 && change[0].1[0] == Change::Value(None, Value::Unsigned(0))
}));
for v in 2..=n {
time += Duration::from_secs(1);
let res = monitor
.accept_event(vec![Value::Unsigned(v)], time)
.expect("Failed to accept value");
assert_eq!(res.event.len(), 0);
if (v - 1) % 4 == 0 {
assert_eq!(res.timed.len(), 1);
assert_eq!(res.timed[0].1[0].1[0], Change::Value(None, Value::Unsigned(v - 1)));
} else {
assert_eq!(res.timed.len(), 0);
}
}
}
#[test]
fn test_spawn_eventbased() {
let (_, mut monitor) = setup::<Total>(
"input a: Int32\n\
input b: Int32\n\
output c(x: Int32) spawn with a eval with x + a\n\
output d := b",
);
let res = monitor
.accept_event(vec![Value::Signed(15), Value::None], Duration::from_secs(1))
.expect("Failed to accept value");
let expected = Total {
inputs: vec![Some(Value::Signed(15)), None],
outputs: vec![
vec![(Some(vec![Value::Signed(15)]), Some(Value::Signed(30)))],
vec![(None, None)],
],
};
assert_eq!(res.event, expected);
assert_eq!(res.timed.len(), 0);
let res = monitor
.accept_event(vec![Value::Signed(20), Value::Signed(7)], Duration::from_secs(2))
.expect("Failed to accept value");
let expected = Total {
inputs: vec![Some(Value::Signed(20)), Some(Value::Signed(7))],
outputs: vec![
vec![
(Some(vec![Value::Signed(15)]), Some(Value::Signed(35))),
(Some(vec![Value::Signed(20)]), Some(Value::Signed(40))),
],
vec![(None, Some(Value::Signed(7)))],
],
};
assert_eq!(sort_total(res.event), sort_total(expected));
assert_eq!(res.timed.len(), 0);
let res = monitor
.accept_event(vec![Value::None, Value::Signed(42)], Duration::from_secs(3))
.expect("Failed to accept value");
let expected = Total {
inputs: vec![Some(Value::Signed(20)), Some(Value::Signed(42))],
outputs: vec![
vec![
(Some(vec![Value::Signed(15)]), Some(Value::Signed(35))),
(Some(vec![Value::Signed(20)]), Some(Value::Signed(40))),
],
vec![(None, Some(Value::Signed(42)))],
],
};
assert_eq!(sort_total(res.event), sort_total(expected));
assert_eq!(res.timed.len(), 0);
}
#[test]
fn test_eval_close() {
let (_, mut monitor) = setup::<Incremental>(
"input a: Int32\n\
output c(x: Int32)\n\
spawn with a \n\
close @a when true\n\
eval with x + a",
);
let res = monitor
.accept_event(vec![Value::Signed(15)], Duration::from_secs(1))
.expect("Failed to accept value");
let mut expected = vec![
Change::Spawn(vec![Value::Signed(15)]),
Change::Value(Some(vec![Value::Signed(15)]), Value::Signed(30)),
Change::Close(vec![Value::Signed(15)]),
];
expected.sort();
assert!(res.timed.is_empty());
assert_eq!(res.event[0].0, 0);
assert_eq!(sort_incremental(res.event)[0].1, expected);
}
}