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

ScheduledTask: Add 'StopExisting' to valid values for MultipleInstances parameter #335

Conversation

Rob-S
Copy link
Contributor

@Rob-S Rob-S commented May 13, 2020

Pull Request (PR) description

Add 'StopExisting' to valid values for ScheduledTask MultipleInstances parameter - fixes Issue #333

This Pull Request (PR) fixes the following issues

Fixes Issue #333

Task list

  • [√] Added an entry under the Unreleased section of the change log in the CHANGELOG.md.
    Entry should say what was changed, and how that affects users (if applicable).
  • [√] Resource documentation added/updated in README.md in resource folder.
  • [√] Resource parameter descriptions added/updated in schema.mof
    and comment-based help.
  • [N/A] Comment-based help added/updated.
  • [N/A] Localization strings added/updated in all localization files as appropriate.
  • [N/A] Examples appropriately added/updated.
  • [√] Unit tests added/updated. See DSC Resource Testing Guidelines.
  • [N/A] Integration tests added/updated (where possible). See DSC Resource Testing Guidelines.
  • [√] New/changed code adheres to DSC Resource Style Guidelines and Best Practices.

This change is Reviewable

@Rob-S
Copy link
Contributor Author

Rob-S commented May 13, 2020

The HQRM tests are failing with the error below for all the examples for every resource, saying Use Import-DSCResource to import the resource. However, the examples do import the resources using the module name: Import-DscResource -ModuleName ComputerManagementDsc. Has something gone awry with the tests?

    Context ScheduledTask\1-ScheduledTask_CreateScheduledTaskOnce_Config.ps1
      [-] Should compile MOFs for example correctly 86ms
        Expected no exception to be thrown, but an exception "At D:\a\1\s\source\Examples\Resources\ScheduledTask\1-ScheduledTask_CreateScheduledTaskOnce_Config.ps1:35 char:9
        +         ScheduledTask ScheduledTaskOnceAdd
        +         ~~~~~~~~~~~~~
        Undefined DSC resource 'ScheduledTask'. Use Import-DSCResource to import the resource." was thrown from D:\a\1\s\source\Examples\Resources\ScheduledTask\1-ScheduledTask_CreateScheduledTaskOnce_Config.ps1:35 char:9
            +         ScheduledTask ScheduledTaskOnceAdd
            +         ~~~~~~~~~~~~~.
        141:                     } | Should -Not -Throw
        at <ScriptBlock>, D:\a\1\s\output\RequiredModules\DscResource.Test\0.13.0\Tests\QA\ExampleFiles.common.Tests.ps1: line 27

@PlagueHO
Copy link
Member

Hi @Rob-S - this is due to a change to recent ModuleBuilder change. I've got a PR #334 open that will resolve it. Once that is trough the build should work properly again.

@PlagueHO
Copy link
Member

You should be able to rebase and resolve conflicts and tests should pass.

@Rob-S
Copy link
Contributor Author

Rob-S commented May 20, 2020

I had resolved the conflict in the CHANGELOG.md file. Does anything else need done on this?

@PlagueHO PlagueHO added the needs review The pull request needs a code review. label May 20, 2020
@PlagueHO
Copy link
Member

Hi @Rob-S - sorry, this is on me. I'll review this weekend (this week is a bit crazy with MS Build and so none of my evenings are free).

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really sorry about the delay in getting this reviewed @Rob-S.

Is it possible to add or update the integration tests to cover this so that we can confirm it will work OK in practice against different OS?

Reviewed 3 of 5 files at r1, 2 of 2 files at r3.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Rob-S)


CHANGELOG.md, line 13 at r3 (raw file):

    by changing `CopyDirectories` to `CopyPaths` - Fixes [Issue #332](https://github.com/dsccommunity/ComputerManagementDsc/issues/332).

- StartedTask

Can you change this to ScheduledTask?


source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1, line 554 at r3 (raw file):

        }

        if ($MultipleInstances -ne 'StopExisting')

Can you add a comment to this code just explaining why it is required? I can see it is covered in the Known Issues, but someone working on this might not see it.

@Rob-S
Copy link
Contributor Author

Rob-S commented Jun 10, 2020

I did try adding a unit test (I took a look at the integration tests, but I'm not really familiar with how those work yet). In the pipeline run, it looks like it's not even trying to run the tests, saying "Cannot bind argument to parameter 'Path' because it is null." although I do see a "Project Path" parameter is set.

@PlagueHO
Copy link
Member

Hi @Rob-S - the build failure is caused by a recent release of Module Builder. I've fixed the issue in this PR #334 - if you rebase onto master again the build should pass - then we can take a look at the integration tests.

@PlagueHO
Copy link
Member

Hi @Rob-S - Sorry, correction, the issue you're seeing is because of the Pester v5.x release. I'm going to pin this module to remain on Pester 4.10.1.

@PlagueHO
Copy link
Member

Once this PR #337 is through you can rebase and the tests will hopefully pass.

…pleInstances-Parameter-Should-Allow-For-'StopExisting'
@PlagueHO
Copy link
Member

@Rob-S - can you try rebasing your branch onto master again to see if that fixes the build?

@PlagueHO
Copy link
Member

@Rob-S
Copy link
Contributor Author

Rob-S commented Jun 17, 2020

@PlagueHO Yes, I had fixed the tests around the same time you entered that comment.

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we need is a unit test that tests when MultipleInstances is set to StopExisting. I could be wrong, but I didn't see one. Is it easy to add that?

Reviewed 1 of 1 files at r5, 1 of 2 files at r7, 1 of 1 files at r9.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @Rob-S)


CHANGELOG.md, line 14 at r9 (raw file):

  - Pin `Pester` module to 4.10.1 because Pester 5.0 is missing code
    coverage - Fixes [Issue #336](https://github.com/dsccommunity/ComputerManagementDsc/issues/336).

Can you remove this blank line?


source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1, line 1832 at r9 (raw file):

    #>
        $MultipleInstances = [System.String] $settings.MultipleInstances
        if ([String]::IsNullOrEmpty($MultipleInstances))

Can you change [String] to [System.String]?


tests/Unit/DSC_ScheduledTask.Tests.ps1, line 115 at r9 (raw file):

                }

                $scheduledTask = $NULL

Can you change to $null (lowercase)

@Rob-S
Copy link
Contributor Author

Rob-S commented Jun 26, 2020

I think what we need is a unit test that tests when MultipleInstances is set to StopExisting. I could be wrong, but I didn't see one. Is it easy to add that?

No. It's easy to add it for the other values, but not for StopExisting, since the Enum does not support that. See the comments for my commits when I attempted to do that. The issue is that you have to go to the SettingsSet level and if you try to mock that function it fails miserably elsewhere -- the "real" SettingsSet functions must be used.

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Rob-S - let's get this through and I'll see if I can figure out away to abstract the function to increase testability on it. As long as it is not breaking any existing functionality (the existing tests confirm that), then we should be OK. I'll raise another issue to increase coverage on that condition.

Reviewed 3 of 3 files at r10.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review The pull request needs a code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants