Test devloop watch policy
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
d0b6c98ac5f097044f86d7cc6a48a114949d1ff1- Parents
-
c5b2e60 - Tree
85501db
d0b6c98
d0b6c98ac5f097044f86d7cc6a48a114949d1ff1c5b2e60
85501db| Status | File | + | - |
|---|---|---|---|
| A |
test/test_devloop_watch.f90
|
102 | 0 |
| M |
test/test_scaffold.f90
|
18 | 1 |
test/test_devloop_watch.f90added@@ -0,0 +1,102 @@ | |||
| 1 | +program test_devloop_watch | ||
| 2 | + use fgof_devloop, only : & | ||
| 3 | + FGOF_DEVLOOP_TRIGGER_CHANGE, & | ||
| 4 | + FGOF_DEVLOOP_TRIGGER_NONE, & | ||
| 5 | + begin_devloop_cycle, & | ||
| 6 | + clear_devloop_options, & | ||
| 7 | + devloop_summarize_watch_events, & | ||
| 8 | + devloop_watch_failure_summary, & | ||
| 9 | + devloop_watch_options, & | ||
| 10 | + devloop_watch_trigger, & | ||
| 11 | + start_devloop | ||
| 12 | + use fgof_devloop_types, only : & | ||
| 13 | + devloop_cycle, & | ||
| 14 | + devloop_options, & | ||
| 15 | + devloop_state, & | ||
| 16 | + devloop_trigger, & | ||
| 17 | + devloop_watch_summary | ||
| 18 | + use fgof_watch_types, only : & | ||
| 19 | + FGOF_WATCH_EVT_CREATED, & | ||
| 20 | + FGOF_WATCH_EVT_MODIFIED, & | ||
| 21 | + FGOF_WATCH_EVT_MOVED, & | ||
| 22 | + FGOF_WATCH_EVT_NONE, & | ||
| 23 | + FGOF_WATCH_EVT_REMOVED, & | ||
| 24 | + watch_event, & | ||
| 25 | + watch_options | ||
| 26 | + implicit none | ||
| 27 | + | ||
| 28 | + type(watch_event) :: events(5) | ||
| 29 | + type(devloop_watch_summary) :: summary | ||
| 30 | + type(devloop_options) :: options | ||
| 31 | + type(devloop_trigger) :: trigger | ||
| 32 | + type(devloop_state) :: state | ||
| 33 | + type(devloop_cycle) :: cycle | ||
| 34 | + type(watch_options) :: watch_config | ||
| 35 | + | ||
| 36 | + events(1)%kind = FGOF_WATCH_EVT_CREATED | ||
| 37 | + events(1)%path = "src/main.f90" | ||
| 38 | + events(2)%kind = FGOF_WATCH_EVT_MODIFIED | ||
| 39 | + events(2)%path = "src/lib.f90" | ||
| 40 | + events(3)%kind = FGOF_WATCH_EVT_REMOVED | ||
| 41 | + events(3)%path = "build" | ||
| 42 | + events(3)%is_directory = .true. | ||
| 43 | + events(4)%kind = FGOF_WATCH_EVT_MOVED | ||
| 44 | + events(4)%path = "test/new.f90" | ||
| 45 | + events(4)%previous_path = "test/old.f90" | ||
| 46 | + events(5)%kind = FGOF_WATCH_EVT_NONE | ||
| 47 | + | ||
| 48 | + summary = devloop_summarize_watch_events(events) | ||
| 49 | + if (summary%event_count /= 5) error stop "watch summary should preserve event count" | ||
| 50 | + if (summary%change_count /= 4) error stop "watch summary should count meaningful changes" | ||
| 51 | + if (summary%file_change_count /= 3) error stop "watch summary should count file changes" | ||
| 52 | + if (summary%directory_change_count /= 1) error stop "watch summary should count directory changes" | ||
| 53 | + if (summary%created_count /= 1) error stop "watch summary should count creates" | ||
| 54 | + if (summary%modified_count /= 1) error stop "watch summary should count modifies" | ||
| 55 | + if (summary%removed_count /= 1) error stop "watch summary should count removes" | ||
| 56 | + if (summary%moved_count /= 1) error stop "watch summary should count moves" | ||
| 57 | + if (summary%ignored_none_count /= 1) error stop "watch summary should ignore none events" | ||
| 58 | + if (.not. summary%has_changes) error stop "watch summary should report changes" | ||
| 59 | + | ||
| 60 | + options = clear_devloop_options() | ||
| 61 | + options%debounce_polls = 2 | ||
| 62 | + options%ignore_hidden = .true. | ||
| 63 | + options%restart_on_directory_change = .false. | ||
| 64 | + watch_config = devloop_watch_options(options) | ||
| 65 | + if (watch_config%debounce_polls /= 2) error stop "watch options should carry debounce policy" | ||
| 66 | + if (.not. watch_config%ignore_hidden) error stop "watch options should carry hidden-path policy" | ||
| 67 | + if (watch_config%emit_directory_events) error stop "watch options should suppress directory events when requested" | ||
| 68 | + | ||
| 69 | + options%debounce_polls = -3 | ||
| 70 | + watch_config = devloop_watch_options(options) | ||
| 71 | + if (watch_config%debounce_polls /= 0) error stop "watch options should clamp negative debounce" | ||
| 72 | + | ||
| 73 | + trigger = devloop_watch_trigger(summary) | ||
| 74 | + if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_CHANGE) error stop "watch changes should create a change trigger" | ||
| 75 | + if (trigger%change_count /= 4) error stop "watch trigger should carry the change count" | ||
| 76 | + | ||
| 77 | + options = clear_devloop_options() | ||
| 78 | + options%restart_on_directory_change = .false. | ||
| 79 | + options%min_restart_changes = 4 | ||
| 80 | + trigger = devloop_watch_trigger(summary, options) | ||
| 81 | + if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) then | ||
| 82 | + error stop "directory-filtered changes below threshold should not restart" | ||
| 83 | + end if | ||
| 84 | + | ||
| 85 | + options%min_restart_changes = 3 | ||
| 86 | + trigger = devloop_watch_trigger(summary, options, "filtered watch") | ||
| 87 | + if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_CHANGE) error stop "file changes at threshold should restart" | ||
| 88 | + if (trigger%change_count /= 3) error stop "filtered watch trigger should carry file count" | ||
| 89 | + if (trigger%reason /= "filtered watch") error stop "watch trigger should preserve custom reason" | ||
| 90 | + | ||
| 91 | + summary = devloop_watch_failure_summary(7, "snapshot failed") | ||
| 92 | + if (.not. summary%watch_failed) error stop "watch failure summary should record failure" | ||
| 93 | + trigger = devloop_watch_trigger(summary) | ||
| 94 | + if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) error stop "watch failures should not force restart triggers" | ||
| 95 | + | ||
| 96 | + call start_devloop(state) | ||
| 97 | + summary = devloop_summarize_watch_events(events(1:2)) | ||
| 98 | + trigger = devloop_watch_trigger(summary) | ||
| 99 | + cycle = begin_devloop_cycle(state, trigger) | ||
| 100 | + if (.not. cycle%started) error stop "watch trigger should drive the devloop cycle model" | ||
| 101 | + if (cycle%change_count /= 2) error stop "watch cycle should preserve trigger change count" | ||
| 102 | +end program test_devloop_watch | ||
test/test_scaffold.f90modified@@ -7,8 +7,15 @@ program test_scaffold | |||
| 7 | clear_devloop_options, & | 7 | clear_devloop_options, & |
| 8 | clear_devloop_state, & | 8 | clear_devloop_state, & |
| 9 | clear_devloop_trigger, & | 9 | clear_devloop_trigger, & |
| 10 | + clear_devloop_watch_summary, & | ||
| 10 | devloop_backend_name | 11 | devloop_backend_name |
| 11 | - use fgof_devloop_types, only : devloop_cycle, devloop_decision, devloop_options, devloop_state, devloop_trigger | 12 | + use fgof_devloop_types, only : & |
| 13 | + devloop_cycle, & | ||
| 14 | + devloop_decision, & | ||
| 15 | + devloop_options, & | ||
| 16 | + devloop_state, & | ||
| 17 | + devloop_trigger, & | ||
| 18 | + devloop_watch_summary | ||
| 12 | implicit none | 19 | implicit none |
| 13 | 20 | ||
| 14 | type(devloop_state) :: state | 21 | type(devloop_state) :: state |
@@ -16,16 +23,22 @@ program test_scaffold | |||
| 16 | type(devloop_trigger) :: trigger | 23 | type(devloop_trigger) :: trigger |
| 17 | type(devloop_cycle) :: cycle | 24 | type(devloop_cycle) :: cycle |
| 18 | type(devloop_decision) :: decision | 25 | type(devloop_decision) :: decision |
| 26 | + type(devloop_watch_summary) :: watch_summary | ||
| 19 | 27 | ||
| 20 | state = clear_devloop_state() | 28 | state = clear_devloop_state() |
| 21 | options = clear_devloop_options() | 29 | options = clear_devloop_options() |
| 22 | trigger = clear_devloop_trigger() | 30 | trigger = clear_devloop_trigger() |
| 23 | cycle = clear_devloop_cycle() | 31 | cycle = clear_devloop_cycle() |
| 24 | decision = clear_devloop_decision() | 32 | decision = clear_devloop_decision() |
| 33 | + watch_summary = clear_devloop_watch_summary() | ||
| 25 | 34 | ||
| 26 | if (state%options%max_failures /= 0) error stop "devloop options should start with unlimited failures" | 35 | if (state%options%max_failures /= 0) error stop "devloop options should start with unlimited failures" |
| 27 | if (.not. state%options%run_on_start) error stop "devloop should default to run on start" | 36 | if (.not. state%options%run_on_start) error stop "devloop should default to run on start" |
| 28 | if (.not. state%options%restart_on_change) error stop "devloop should default to restart on change" | 37 | if (.not. state%options%restart_on_change) error stop "devloop should default to restart on change" |
| 38 | + if (.not. state%options%restart_on_directory_change) error stop "devloop should restart on directory changes by default" | ||
| 39 | + if (state%options%ignore_hidden) error stop "devloop should not ignore hidden paths by default" | ||
| 40 | + if (state%options%min_restart_changes /= 1) error stop "devloop should restart after one change by default" | ||
| 41 | + if (state%options%debounce_polls /= 0) error stop "devloop should not debounce by default" | ||
| 29 | if (state%last_cycle%id /= 0) error stop "devloop state should clear the last cycle" | 42 | if (state%last_cycle%id /= 0) error stop "devloop state should clear the last cycle" |
| 30 | if (state%cycle_count /= 0) error stop "devloop state should start with no cycles" | 43 | if (state%cycle_count /= 0) error stop "devloop state should start with no cycles" |
| 31 | if (state%consecutive_failures /= 0) error stop "devloop state should start with no failures" | 44 | if (state%consecutive_failures /= 0) error stop "devloop state should start with no failures" |
@@ -36,5 +49,9 @@ program test_scaffold | |||
| 36 | if (cycle%started) error stop "clear cycle should not start a cycle" | 49 | if (cycle%started) error stop "clear cycle should not start a cycle" |
| 37 | if (decision%kind /= FGOF_DEVLOOP_DECISION_IDLE) error stop "clear decision should idle" | 50 | if (decision%kind /= FGOF_DEVLOOP_DECISION_IDLE) error stop "clear decision should idle" |
| 38 | if (options%stop_on_failure) error stop "clear options should not stop on failure by default" | 51 | if (options%stop_on_failure) error stop "clear options should not stop on failure by default" |
| 52 | + if (options%ignore_hidden) error stop "clear options should not ignore hidden paths by default" | ||
| 53 | + if (options%debounce_polls /= 0) error stop "clear options should not debounce by default" | ||
| 54 | + if (watch_summary%has_changes) error stop "clear watch summary should not have changes" | ||
| 55 | + if (watch_summary%watch_failed) error stop "clear watch summary should not fail" | ||
| 39 | if (devloop_backend_name() /= "model") error stop "devloop backend should report model" | 56 | if (devloop_backend_name() /= "model") error stop "devloop backend should report model" |
| 40 | end program test_scaffold | 57 | end program test_scaffold |