Debian Codegraph @

testsuite/modules.30-cache/052-cache-expiry-secs.exp

raw
1 ##############################################################################
2 # Modules Revision 3.0
3 # Providing a flexible user environment
4 #
5 # File: modules.30-cache/%M%
6 # Revision: %I%
7 # First Edition: 2022/12/07
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: Xavier Delaruelle, [email protected]
11 #
12 # Description: Testuite testsequence
13 # Command: avail, whatis, load
14 # Modulefiles:
15 # Sub-Command:
16 #
17 # Comment: %C{
18 # Test cache_expiry_secs configuration option
19 # }C%
20 #
21 ##############################################################################
22
23 skip_if_quick_mode
24
25 # ensure avail tests are made using in depth mode
26 setenv_var MODULES_AVAIL_INDEPTH 1
27
28 # generate content in modulepaths
29 lassign [create_simple_module_setup $mp1] dir_list file_list
30 array set file_arr $file_list
31
32 setenv_var MODULEPATH $mp1
33
34 # create empty cache file
35 create_dummy_cachefile $mp1
36
37 set tserr_avail_cache {}
38 set tserr_avail_nocache "$mp1:
39 bar/1.0
40 bar/2.0
41 foo/1.0"
42 set ans_load_cache ERR
43 set tserr_load_cache $err_path'bar/1.0'
44 set ans_load_nocache [list]
45 lappend ans_load_nocache [list set _LMFILES_ $mp1/bar/1.0]
46 lappend ans_load_nocache [list set LOADEDMODULES bar/1.0]
47
48 set now_secs [clock seconds]
49 set more_than_one_hour_ago [expr {$now_secs - 3600 - 1}]
50 set more_than_one_month_ago [expr {$now_secs - (3600*24*30) - 1}]
51 set more_than_one_year_ago [expr {$now_secs - (3600*24*365) - 1}]
52
53 # expiration disabled
54 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
55 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
56 file mtime $mp1cache $more_than_one_year_ago
57 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
58 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
59
60 setenv_var MODULES_CACHE_EXPIRY_SECS 0
61 file mtime $mp1cache $now_secs
62 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
63 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
64 file mtime $mp1cache $more_than_one_month_ago
65 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
66 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
67
68 # expiration after 1 hour
69 setenv_var MODULES_CACHE_EXPIRY_SECS 3600
70 file mtime $mp1cache $now_secs
71 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
72 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
73 file mtime $mp1cache $more_than_one_hour_ago
74 testouterr_cmd sh {avail -t} OK $tserr_avail_nocache
75 testouterr_cmd sh {load bar/1.0} $ans_load_nocache {}
76 file mtime $mp1cache $more_than_one_month_ago
77 testouterr_cmd sh {avail -t} OK $tserr_avail_nocache
78 testouterr_cmd sh {load bar/1.0} $ans_load_nocache {}
79 file mtime $mp1cache $more_than_one_year_ago
80 testouterr_cmd sh {avail -t} OK $tserr_avail_nocache
81 testouterr_cmd sh {load bar/1.0} $ans_load_nocache {}
82
83 # expiration after 1 month
84 setenv_var MODULES_CACHE_EXPIRY_SECS [expr {3600*24*30}]
85 file mtime $mp1cache $now_secs
86 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
87 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
88 file mtime $mp1cache $more_than_one_hour_ago
89 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
90 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
91 file mtime $mp1cache $more_than_one_month_ago
92 testouterr_cmd sh {avail -t} OK $tserr_avail_nocache
93 testouterr_cmd sh {load bar/1.0} $ans_load_nocache {}
94 file mtime $mp1cache $more_than_one_year_ago
95 testouterr_cmd sh {avail -t} OK $tserr_avail_nocache
96 testouterr_cmd sh {load bar/1.0} $ans_load_nocache {}
97
98 # expiration after 1 year
99 setenv_var MODULES_CACHE_EXPIRY_SECS [expr {3600*24*365}]
100 file mtime $mp1cache $now_secs
101 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
102 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
103 file mtime $mp1cache $more_than_one_hour_ago
104 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
105 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
106 file mtime $mp1cache $more_than_one_month_ago
107 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
108 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
109 file mtime $mp1cache $more_than_one_year_ago
110 testouterr_cmd sh {avail -t} OK $tserr_avail_nocache
111 testouterr_cmd sh {load bar/1.0} $ans_load_nocache {}
112
113 # erroneous expiration delay
114 setenv_var MODULES_CACHE_EXPIRY_SECS -1000
115 file mtime $mp1cache $now_secs
116 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
117 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
118 file mtime $mp1cache $more_than_one_hour_ago
119 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
120 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
121 file mtime $mp1cache $more_than_one_month_ago
122 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
123 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
124 file mtime $mp1cache $more_than_one_year_ago
125 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
126 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
127
128 setenv_var MODULES_CACHE_EXPIRY_SECS foo
129 file mtime $mp1cache $now_secs
130 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
131 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
132 file mtime $mp1cache $more_than_one_hour_ago
133 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
134 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
135 file mtime $mp1cache $more_than_one_month_ago
136 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
137 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
138 file mtime $mp1cache $more_than_one_year_ago
139 testouterr_cmd sh {avail -t} OK $tserr_avail_cache
140 testouterr_cmd sh {load bar/1.0} $ans_load_cache $tserr_load_cache
141
142
143 # cannot test access if cannot change file permission
144 if {!$is_file_perms_editable} {
145 send_user "\tskipping access tests as file permissions cannot be changed\n"
146 # cannot test access if superuser privileges are in use
147 } elseif {$tcl_platform(user) eq "root"} {
148 send_user "\tskipping access tests as tests are run by superuser\n"
149 # cannot test access if restricted file permissions have no effect
150 } elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
151 send_user "\tskipping access tests as locked files or directories are still readable\n"
152 } else {
153
154 # check expected siteconfig file is installed
155 set is_stderr_tty [siteconfig_isStderrTty]
156 if {$is_stderr_tty} {
157 # test a cache read failure by faking cache file is readable
158 setenv_var TESTSUITE_ENABLE_SITECONFIG_CACHE_READ 1
159
160 set tserr [err_permdenied $mp1cache]\n$err_path'bar/1.0'
161
162 setenv_var MODULES_CACHE_EXPIRY_SECS 3600
163 file mtime $mp1cache $now_secs
164 change_file_perms $mp1 ugo-rx
165 testouterr_cmd sh {avail -t} OK {}
166 testouterr_cmd sh {load bar/1.0} ERR $tserr
167 restore_file_perms $mp1
168
169 file mtime $mp1cache $more_than_one_hour_ago
170 change_file_perms $mp1 ugo-rx
171 testouterr_cmd sh {avail -t} OK {}
172 testouterr_cmd sh {load bar/1.0} ERR $tserr
173 restore_file_perms $mp1
174 unsetenv_var TESTSUITE_ENABLE_SITECONFIG_CACHE_READ
175 }
176
177 }
178
179
180 #
181 # Cleanup
182 #
183
184 file delete $mp1cache
185
186 # delete created files and dirs
187 delete_module_setup $mp1 [array names file_arr] $dir_list
188
189 reset_test_env