Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

we should allow user to override default PROFTD_TEST_PATH #1525

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sashan
Copy link
Contributor

@Sashan Sashan commented Aug 21, 2022

ftpcount, ftpwho programs should not run in backround to avoid a race with test script

let fpdctl to derive correct path from PROFTPD_TEST_PATH (when specified)

ftpcount, ftpwho programs should not run in backround to avoid a race with test script

let fpdctl to derive correct path from PROFTPD_TEST_PATH (when specified)
@Castaglia
Copy link
Member

Can you provide the actual errors/issues that you're encountering? I'm far more likely to accept these PRs if I can understand, reproduce the context behind them.

@Sashan
Copy link
Contributor Author

Sashan commented Aug 25, 2022

ctrls_lsctrl_system_user_ok and ctrls_lsctrl_ok tests in t/modules/mod_ctrls.t both fail with error as follows:

Executing ftpdctl: /scratch/userland-gate/components/proftpd/proftpd-1.3.8rc4/tests//../ftpdctl -s /tmp/proftpd-test-3509-test2-ulA38XKwoo/ctrls.sock lsctrl                                                                    
Can't exec "/scratch/userland-gate/components/proftpd/proftpd-1.3.8rc4/tests//../ftpdctl": No such file or directory at t/lib/ProFTPD/Tests/Modules/mod_ctrls.pm line 68.                                                       
Stopping server: kill -TERM 3517                                                                                                                                                                                                
                                                                                                                                                                                                                                
not ok ERROR ctrls_lsctrl_system_user_ok                                                                                                                                                                                        
t/lib/ProFTPD/Tests/Modules/mod_ctrls.pm:266 - ctrls_lsctrl_system_user_ok(ProFTPD::Tests::Modules::mod_ctrls)

both tests are not able to locate ftpdctl binary. test case assumes that in runs from source directory /scratch/userland-gate/components/proftpd/proftpd-1.3.8rc4 which also contains binaries. However this is not true. We run test from build directory: /scratch/userland-gate/components/proftpd/build/amd64/tests therefore we need to specify PROFTD_TEST_PATH, so test can deduce a location of ftpdctl:

 54   my $ftpdctl_bin;                                                                                                                                                                                                          
 55   if ($ENV{PROFTPD_TEST_PATH}) {                                                                                                                                                                                            
 56     $ftpdctl_bin = "$ENV{PROFTPD_TEST_PATH}/../ftpdctl";                                                                                                                                                                    
 57                                                                                                                                                                                                                             
 58   } else {                                                                                                                                                                                                                  
 59     $ftpdctl_bin = '../ftpdctl';                                                                                                                                                                                            
 60   }                              

also running a tool in background fixes a race. consider we run ftpwho/ftpcount in background. Like we do here:

 51 sub ftpwho {                                                                                                                                                                                                                
 52   my $scoreboard_file = shift;                                                                                                                                                                                              
 53   my $ftpwho_opts = shift;                                                                                                                                                                                                  
 54   $ftpwho_opts = '' unless defined($ftpwho_opts);                                                                                                                                                                           
 55   my $output_file = shift;                                                                                                                                                                                                  
 56   my $ftpwho_wait_timeout = shift;                                                                                                                                                                                          
 57   $ftpwho_wait_timeout = 1 unless defined($ftpwho_wait_timeout);                                                                                                                                                            
 58                                                                                                                                                                                                                             
 59   my $ftpwho_bin;                                                                                                                                                                                                           
 60   if ($ENV{PROFTPD_TEST_PATH}) {                                                                                                                                                                                            
 61     $ftpwho_bin = "$ENV{PROFTPD_TEST_PATH}/../ftpwho";                                                                                                                                                                      
 62                                                                                                                                                                                                                             
 63   } else {                                                                                                                                                                                                                  
 64     $ftpwho_bin = '../ftpwho';                                                                                                                                                                                              
 65   }                                                                                                                                                                                                                         
 66                                                                                                                                                                                                                             
 67   my $cmd = "$ftpwho_bin -f $scoreboard_file $ftpwho_opts >$output_file 2>/dev/null &";                                                                                                                                       
 68                                                                                                                                                                                                                             
 69   if ($ENV{TEST_VERBOSE}) {                                                                                                                                                                                                 
 70     print STDERR "Executing ftpwho: $cmd\n";                                                                                                                                                                                
 71   }                                         
...
150   if ($pid) {                                                                                                                                                                                                               
151     eval {                                                                                                                                                                                                                  
152       my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);                                                                                                                                                        
153       $client->login($user, $passwd);                                                                                                                                                                                       
154                                                                                                                                                                                                                             
155       # Before we stop the server, use ftpwho to read the scoreboard                                                                                                                                                        
156       ftpwho($scoreboard_file, '', $ftpwho_file);                                                                                                                                                                           
157                                                                                                                                                                                                                             
158       $client->quit();                                                                                                                                                                                                      
159     };                                          

at line 156 we spawn a ftpwho too, which will supposedly run in background. OS forks a background process, however it does not mean the process will ever run on CPU before parent (our test script) will call $client->quit() at line 158. Therefore we have to let test to run ftpwho in foreground, so line 158 ($client->quit()) will be executed after ftpsho will be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants