Skip to content

Fix unit tests mutating the system#22921

Closed
haampie wants to merge 12 commits intospack:developfrom
haampie:fix-tests-mutating-the-system
Closed

Fix unit tests mutating the system#22921
haampie wants to merge 12 commits intospack:developfrom
haampie:fix-tests-mutating-the-system

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented Apr 10, 2021

This is a bunch of fixes needed to make most of the tests pass on a readonly filesystem.

Ping @becker33 / @alalazo.

Closes #22920

@haampie haampie force-pushed the fix-tests-mutating-the-system branch from 6ab76e5 to fa697c6 Compare April 12, 2021 16:10
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Apr 12, 2021

Currently:

test_changed_files  -- setup             /tmp/.mount_spack.LH5QIT/spack/var/spack/repos/builtin.mock/packages/flake8/package.py~
test_is_git_repo_in_worktree -- setup    fatal: could not create leading directories of '.git/worktrees/tmp_worktree': Read-only file system


test_buildcache_create_fail_on_perm_denied
- Failed: DID NOT RAISE <class 'OSError'>

TestConcretize.test_no_matching_compiler_specs
- lib/spack/spack/concretize.py:710: NoCompilersForArchError

test_100_no_write_with_exception_on_remove
- assert len(database.query('mpileaks ^zmpi', installed=any)) == 1
  assert 0 == 1

test_110_no_write_with_exception_on_install
- assert database.query('cmake', installed=any) == []
  assert [[email protected]%...debian6-core2] == []

test_function_calls[-a-effects5]
- os.unlink(entry.name, dir_fd=topfd)
  calls clean
  OSError: [Errno 30] Read-only file system: 'uninstall.cpython-38.pyc'

test_upgrade_read_to_write_fails_with_readonly_file
- assert lock._file.mode == 'r'
  assert 'r+' == 'r'

@tldahlgren tldahlgren requested review from alalazo and becker33 April 12, 2021 18:27
@tldahlgren tldahlgren added the tests General test capability(ies) label Apr 12, 2021
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Apr 12, 2021

Oh, I forgot to set SPACK_TEST_SOLVER=clingo. Now it's down to 2 failing tests:

______________________________________________ TestConcretize.test_no_matching_compiler_specs _______________________________________________                                                                                                                                             
                                                                                                                                                                                                                                                                                          
self = <spack.test.concretize.TestConcretize object at 0x7f1d62f2aac0>                                                                                                                                                                                                                    
mock_low_high_config = <spack.config.Configuration object at 0x7f1d6359a2e0>                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                          
    def test_no_matching_compiler_specs(self, mock_low_high_config):                                                                                                                                                                                                                      
        # only relevant when not building compilers as needed                                                                                                                                                                                                                             
        with spack.concretize.enable_compiler_existence_check():                                                                                                                                                                                                                          
            s = Spec('a %[email protected]')                                                                                                                                                                                                                                                      
            with pytest.raises(                                                                                                                                                                                                                                                           
                    spack.concretize.UnavailableCompilerVersionError):                                                                                                                                                                                                                    
>               s.concretize()                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                          
lib/spack/spack/test/concretize.py:379:                                                                                                                                                                                                                                                   
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                                                                                                                                             
lib/spack/spack/spec.py:2573: in concretize                                                                                                                                                                                                                                               
    self._old_concretize(tests)                                                                                                                                                                                                                                                           
lib/spack/spack/spec.py:2373: in _old_concretize                                                                                                                                                                                                                                          
    self._concretize_helper(concretizer))                                                                                                                                                                                                                                                 
lib/spack/spack/spec.py:2208: in _concretize_helper                                                                                                                                                                                                                                       
    concretizer.concretize_compiler(self),                                                                                                                                                                                                                                                
lib/spack/spack/concretize.py:445: in concretize_compiler                                                                                                                                                                                                                                 
    _compiler_concretization_failure(                                                                                                                                                                                                                                                     
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                                                                                                                                             
                                                                                                                                                                                                                                                                                          
compiler_spec = [email protected], arch = test-debian6-core2                                                                                                                                                                                                                                      
                                                                      
    def _compiler_concretization_failure(compiler_spec, arch):                                                                               
        # Distinguish between the case that there are compilers for                                                                          
        # the arch but not with the given compiler spec and the case that                                                                    
        # there are no compilers for the arch at all                  
        if not spack.compilers.compilers_for_arch(arch):
            available_os_targets = set(                                                                                                      
                (c.operating_system, c.target) for c in
                spack.compilers.all_compilers())                                                                                             
>           raise NoCompilersForArchError(arch, available_os_targets)                                                                        
E           spack.concretize.NoCompilersForArchError: No compilers found for operating system debian6 and target core2.                      
E           If previous installations have succeeded, the operating system may have been updated.                                            
E           Compilers are defined for the following operating systems and targets:                                                           
E                                                                                                                                            
E               Run 'spack compiler find' to add compilers.                                                                                  

lib/spack/spack/concretize.py:710: NoCompilersForArchError                                                                                   

and

_____________________________________________________ test_function_calls[-a-effects5] ______________________________________________________                                                                                                                                    [19/1869]
                                                                      
command_line = '-a', effects = ['stages', 'downloads', 'caches', 'failures']                                                                 
mock_calls_for_clean = {'caches': 1, 'downloads': 1, 'failures': 1, 'package': 0, ...}                                                       
                                                                                                                                             
    @pytest.mark.usefixtures(                                         
        'mock_packages', 'config'  
    )                                                                 
    @pytest.mark.parametrize('command_line,effects', [                                                                                       
        ('mpileaks', ['package']),                                    
        ('-s',       ['stages']),
        ('-sd',      ['stages', 'downloads']),       
        ('-m',       ['caches']),                                     
        ('-f',       ['failures']),                         
        ('-a',       all_effects),                                    
        ('',         []),                                             
    ])                                                                
    def test_function_calls(command_line, effects, mock_calls_for_clean):                                                                    
                                   
        # Call the command with the supplied command line          
>       clean(command_line)                                           

lib/spack/spack/test/cmd/clean.py:60: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
lib/spack/spack/main.py:555: in __call__
    self.returncode = _invoke_command(
lib/spack/spack/main.py:496: in _invoke_command
    return_val = command(parser, args)
lib/spack/spack/cmd/clean.py:102: in clean
    shutil.rmtree(dname)                                              
../view/lib/python3.8/shutil.py:718: in rmtree
    _rmtree_safe_fd(fd, path, onerror)
../view/lib/python3.8/shutil.py:675: in _rmtree_safe_fd
    onerror(os.unlink, fullname, sys.exc_info())
...
>                   os.unlink(entry.name, dir_fd=topfd)
E                   OSError: [Errno 30] Read-only file system: 'uninstall.cpython-38.pyc'

../view/lib/python3.8/shutil.py:673: OSError

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Apr 12, 2021

Okay, this seems done. All relevant tests pass now!

2637 passed, 148 skipped, 8 xfailed, 1 xpassed, 2 error in 609.87 seconds

The 2 errors are:

  • test_is_git_repo_in_worktree (writes into .git folder -- doesn't work)
  • test_changed_files -- (flake8 wants to create [filename].py~ files which doesn't work)

Can I somehow mark those a skipped when the spack root folder is readonly?

This reverts commit 5e6b469.

Seems like this wasn't necessary at all
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 27, 2021

I don't really feel like rebasing this

@haampie haampie closed this Oct 27, 2021
@tldahlgren tldahlgren changed the title Fix tests mutating the system Fix unit tests mutating the system Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests General test capability(ies)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit tests write to <spack>/opt/ folder.

3 participants