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

(FACT-3465) Order dependent failures #2715

Merged
merged 5 commits into from
May 23, 2024

Conversation

joshcooper
Copy link
Contributor

Previously, the uname resolver set an instance_spy logger, but didn't clear it. If the uname spec was run first, followed by another spec whose resolver relied on the uname resolver, then the instance_spy would leak across specs. This clears the logger and fixes several tests that were passing for the wrong reasons.

The "loggers leak across tests" is a general issue. It will be fixed in a separate issue:

$ git grep -l 'instance_variable_set(:@log' spec/facter/resolvers/ | xargs git grep -L 'instance_variable_set(:@log, nil)' 
spec/facter/resolvers/aix/disks_spec.rb
spec/facter/resolvers/aix/memory_spec.rb
spec/facter/resolvers/aix/mountpoints_spec.rb
spec/facter/resolvers/aix/networking_spec.rb
spec/facter/resolvers/aix/os_level_spec.rb
spec/facter/resolvers/aix/partitions_spec.rb
spec/facter/resolvers/aix/processors_spec.rb
spec/facter/resolvers/amzn/os_release_rpm_spec.rb
spec/facter/resolvers/augeas_spec.rb
spec/facter/resolvers/az_spec.rb
spec/facter/resolvers/bsd/processors_spec.rb
spec/facter/resolvers/freebsd/processors_spec.rb
spec/facter/resolvers/freebsd/swap_memory_spec.rb
spec/facter/resolvers/freebsd/system_memory_spec.rb
spec/facter/resolvers/hostname_spec.rb
spec/facter/resolvers/linux/docker_uptime_spec.rb
spec/facter/resolvers/linux/hostname_spec.rb
spec/facter/resolvers/linux/lscpu_spec.rb
spec/facter/resolvers/linux/networking_spec.rb
spec/facter/resolvers/lpar_spec.rb
spec/facter/resolvers/lspci_spec.rb
spec/facter/resolvers/macosx/dmi_spec.rb
spec/facter/resolvers/macosx/filesystems_spec.rb
spec/facter/resolvers/macosx/load_averages_spec.rb
spec/facter/resolvers/macosx/processors_spec.rb
spec/facter/resolvers/macosx/swap_memory_spec.rb
spec/facter/resolvers/macosx/system_memory_spec.rb
spec/facter/resolvers/mountpoints_spec.rb
spec/facter/resolvers/networking_spec.rb
spec/facter/resolvers/openbsd/mountpoints_spec.rb
spec/facter/resolvers/partitions_spec.rb
spec/facter/resolvers/selinux_spec.rb
spec/facter/resolvers/solaris/dmi_sparc_spec.rb
spec/facter/resolvers/solaris/dmi_spec.rb
spec/facter/resolvers/solaris/filesystem_spec.rb
spec/facter/resolvers/solaris/ipaddress_spec.rb
spec/facter/resolvers/solaris/ldom_spec.rb
spec/facter/resolvers/solaris/memory_spec.rb
spec/facter/resolvers/solaris/zone_name_spec.rb
spec/facter/resolvers/solaris/zone_spec.rb
spec/facter/resolvers/sw_vers_spec.rb
spec/facter/resolvers/system_profile_spec.rb
spec/facter/resolvers/virt_what_spec.rb
spec/facter/resolvers/vmware_spec.rb
spec/facter/resolvers/windows/dmi_bios_spec.rb
spec/facter/resolvers/windows/dmi_computersystem_spec.rb
spec/facter/resolvers/windows/kernel_spec.rb
spec/facter/resolvers/windows/memory_spec.rb
spec/facter/resolvers/windows/networking_spec.rb
spec/facter/resolvers/windows/processors_spec.rb
spec/facter/resolvers/windows/system32_spec.rb
spec/facter/resolvers/windows/uptime_spec.rb
spec/facter/resolvers/windows/virtualization_spec.rb
spec/facter/resolvers/windows/win_os_description_spec.rb
spec/facter/resolvers/wpar_spec.rb
spec/facter/resolvers/xen_spec.rb
spec/facter/resolvers/zfs_spec.rb
spec/facter/resolvers/zpool_spec.rb

@joshcooper joshcooper force-pushed the order-dependent-failures branch 2 times, most recently from b4ec575 to faa5a1b Compare May 17, 2024 21:19
@joshcooper joshcooper marked this pull request as ready for review May 17, 2024 22:07
@joshcooper joshcooper requested a review from a team as a code owner May 17, 2024 22:07
The uname spec set a logger class variable on the uname resolver which leaked
into the processor spec. This wasn't noticed until the processor resolver was
modified to call the uname resolver. So the instance spy from the uname
resolver spec leaked into the processor spec:

    C:\> bundle exec rspec -fd .\spec\facter\resolvers\uname_spec.rb:32 .\spec\facter\resolvers\processors_spec.rb:182
    ...
    1) Facter::Resolvers::Linux::Processors when on powerpc architecture
    returns list of models
    Failure/Error: logger.debug(format(STDERR_MESSAGE, command, msg.strip))
    #<InstanceDouble(Facter::Log) (anonymous)> was originally created in one
    example but has leaked into another example and can no longer be used.
Running the ec2_spec test in isolation failed on Windows because the call to
Socket.tcp would timeout and skip the rest of the code being tested.
The RSpec `allow` method creates a proxy object to wrap the original object.
This way it can intercept calls to the original object that are "allowed".
However, if the proxy receives a method that isn't allowed, then it will raise
an RSpec exception. Several tests were rescuing the RSpec exception, but still
passing (for the wrong reason).

The rule is if you stub an object and it might be called with other arguments,
then you need to add `and_call_original`. This is especially true for
File.exist? because it's called by rubygems.
We use instance_spys for the logger everywhere else.
Previously if neither /sur/sbin/xl nor xm existed, then the `find_command`
method returned the array of XEN_COMMANDS. Since that wasn't nil, the resolver
tried to execute the Array of commands and failed (for the wrong reason).

Now explicitly return nil in the case neither file exists.
@joshcooper joshcooper changed the title Order dependent failures (FACT-3465) Order dependent failures May 20, 2024
@joshcooper joshcooper closed this May 22, 2024
@joshcooper joshcooper reopened this May 22, 2024
@joshcooper joshcooper added the bug Something isn't working label May 22, 2024
@cthorn42 cthorn42 merged commit 2ab655b into puppetlabs:main May 23, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants