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

Use an AA to index test suites #287

Merged
merged 3 commits into from
Jul 1, 2024
Merged

Use an AA to index test suites #287

merged 3 commits into from
Jul 1, 2024

Conversation

luis-soares-sky
Copy link
Contributor

@luis-soares-sky luis-soares-sky commented Jun 25, 2024

Rooibos currently uses an if-switch statement block to determine which test suites should be run. This results in lots of duplicate code, and usually having a Roku compiler error due to bytecode chunk constant limitations when too many test suites are present.

------ Compiling dev 'unit-tests-v5' ------
*** ERROR compiling pkg:/source/rooibos/RuntimeConfig.brs(NaN)
06-25 18:31:42.680 [plg.dbg.conn.wait] Waiting for debugging connection
06-25 18:31:42.690 [plg.dbg.conn.wait] Waiting for debugger on 10.18.5.243:8081
06-25 18:31:42.697 [plg.dbg.conn.ok] remote debugger connected
Internal limit size exceeded. (compile error &hae) in pkg:/source/rooibos/RuntimeConfig.brs(734)

This happens with the latest Rooibos version when I have >=300 test suites. I usually have to batch them so the devices in my CI don't freak out.

Here's an example of what source/rooibos/RuntimeConfig.brs looks like at the moment:

    instance.getTestSuiteClassWithName = function(name)
        if false
            ? "noop"
        else if name = "AtlantisInitCompleteEventCommandTests"
            return tests_AtlantisInitCompleteEventCommandTests
        else if name = "AppLaunchedCommandTests"
            return tests_AppLaunchedCommandTests
        else if name = "ArrayUtilsTests"
            return tests_ArrayUtilsTests
        else if name = "AppPopupConfirmationPageControllerTests"
            return tests_AppPopupConfirmationPageControllerTests
        else if name = "AudioSubtitlesModelTests"
            return tests_AudioSubtitlesModelTests
        else if name = "AddToSmartlistCommandTests"
            return tests_AddToSmartlistCommandTests
        else if name = "ABModelTests"
            return tests_ABModelTests
        else if name = "AuthenticationServiceAuthenticateErrorAdaptorTests"
            return tests_AuthenticationServiceAuthenticateErrorAdaptorTests
        else if name = "AuthenticationServiceSuccessResponseAdapterTests"
            return tests_AuthenticationServiceSuccessResponseAdapterTests
        else if name = "AccountPageControllerTests"
            return tests_AccountPageControllerTests
        else if name = "AuthenticationServiceCaptchaAdapterTests"
            return tests_AuthenticationServiceCaptchaAdapterTests
        else if name = "AuthenticationServiceSignUpErrorResponseAdapterTests"
            return tests_AuthenticationServiceSignUpErrorResponseAdapterTests
        else if name = "AuthenticationServiceSignInErrorAdapterTests"
            return tests_AuthenticationServiceSignInErrorAdapterTests
        else if name = "ABServiceTests"
            return tests_ABServiceTests
        else if name = "AuthenticationAgentTests"
            return tests_AuthenticationAgentTests
        else if name = "AbstractAssetDecoratorTests"
            return tests_AbstractAssetDecoratorTests
        else if name = "AbstractMenuDecoratorTests"
            return tests_AbstractMenuDecoratorTests
        else if name = "AuthenticationServiceTests"
            return tests_AuthenticationServiceTests
        else if name = "AbstractSeasonSeriesDecoratorTests"
            return tests_AbstractSeasonSeriesDecoratorTests
        else if name = "AssetEpisodeDecoratorTests"
            return tests_AssetEpisodeDecoratorTests
        else if name = "AssetLinearSlotDecoratorTests"
            return tests_AssetLinearSlotDecoratorTests
        else if name = "AssetLinearDecoratorTests"
            return tests_AssetLinearDecoratorTests
        else if name = "AssetSLEDecoratorTests"
            return tests_AssetSLEDecoratorTests
        else if name = "AssetShortformDecoratorTests"
            return tests_AssetShortformDecoratorTests
        else if name = "AtlantisUtilsTests"
            return tests_AtlantisUtilsTests
        else if name = "AsyncMessageEntitlementsChangedCommandTests"
            return tests_AsyncMessageEntitlementsChangedCommandTests
        else if name = "AssetMovieDecoratorTests"
            return tests_AssetMovieDecoratorTests
        else if name = "AsyncGetSettingsNodeJobTests"
            return tests_AsyncGetSettingsNodeJobTests
        else if name = "AsyncNotificationsModelTests"
            return tests_AsyncNotificationsModelTests
        else if name = "AsyncNotificationsServiceTests"
            return tests_AsyncNotificationsServiceTests
        else if name = "AuthenticationServiceSignInTemplateAdapterTests"
            return tests_AuthenticationServiceSignInTemplateAdapterTests
        end if
    end function
    instance.getAllTestSuitesNames = function()
        return [
            "AtlantisInitCompleteEventCommandTests"
            "AppLaunchedCommandTests"
            "ArrayUtilsTests"
            "AppPopupConfirmationPageControllerTests"
            "AudioSubtitlesModelTests"
            "AddToSmartlistCommandTests"
            "ABModelTests"
            "AuthenticationServiceAuthenticateErrorAdaptorTests"
            "AuthenticationServiceSuccessResponseAdapterTests"
            "AccountPageControllerTests"
            "AuthenticationServiceCaptchaAdapterTests"
            "AuthenticationServiceSignUpErrorResponseAdapterTests"
            "AuthenticationServiceSignInErrorAdapterTests"
            "ABServiceTests"
            "AuthenticationAgentTests"
            "AbstractAssetDecoratorTests"
            "AbstractMenuDecoratorTests"
            "AuthenticationServiceTests"
            "AbstractSeasonSeriesDecoratorTests"
            "AssetEpisodeDecoratorTests"
            "AssetLinearSlotDecoratorTests"
            "AssetLinearDecoratorTests"
            "AssetSLEDecoratorTests"
            "AssetShortformDecoratorTests"
            "AtlantisUtilsTests"
            "AsyncMessageEntitlementsChangedCommandTests"
            "AssetMovieDecoratorTests"
            "AsyncGetSettingsNodeJobTests"
            "AsyncNotificationsModelTests"
            "AsyncNotificationsServiceTests"
            "AuthenticationServiceSignInTemplateAdapterTests"
        ]
    end function

This PR changes that to use an AA instead, which uses up less code:

    instance.getTestSuiteClassMap = function()
        return {
            "ABModelTests": tests_ABModelTests
            "ABServiceTests": tests_ABServiceTests
            "AbstractAssetDecoratorTests": tests_AbstractAssetDecoratorTests
            "AbstractMenuDecoratorTests": tests_AbstractMenuDecoratorTests
            "AbstractSeasonSeriesDecoratorTests": tests_AbstractSeasonSeriesDecoratorTests
            "AccountPageControllerTests": tests_AccountPageControllerTests
            "AddToSmartlistCommandTests": tests_AddToSmartlistCommandTests
            "AppLaunchedCommandTests": tests_AppLaunchedCommandTests
            "AppPopupConfirmationPageControllerTests": tests_AppPopupConfirmationPageControllerTests
            "ArrayUtilsTests": tests_ArrayUtilsTests
            "AssetEpisodeDecoratorTests": tests_AssetEpisodeDecoratorTests
            "AssetLinearDecoratorTests": tests_AssetLinearDecoratorTests
            "AssetLinearSlotDecoratorTests": tests_AssetLinearSlotDecoratorTests
            "AssetMovieDecoratorTests": tests_AssetMovieDecoratorTests
            "AssetShortformDecoratorTests": tests_AssetShortformDecoratorTests
            "AssetSLEDecoratorTests": tests_AssetSLEDecoratorTests
            "AsyncGetSettingsNodeJobTests": tests_AsyncGetSettingsNodeJobTests
            "AsyncMessageEntitlementsChangedCommandTests": tests_AsyncMessageEntitlementsChangedCommandTests
            "AsyncNotificationsModelTests": tests_AsyncNotificationsModelTests
            "AsyncNotificationsServiceTests": tests_AsyncNotificationsServiceTests
            "AtlantisInitCompleteEventCommandTests": tests_AtlantisInitCompleteEventCommandTests
            "AtlantisUtilsTests": tests_AtlantisUtilsTests
            "AudioSubtitlesModelTests": tests_AudioSubtitlesModelTests
            "AuthenticationAgentTests": tests_AuthenticationAgentTests
            "AuthenticationServiceAuthenticateErrorAdaptorTests": tests_AuthenticationServiceAuthenticateErrorAdaptorTests
            "AuthenticationServiceCaptchaAdapterTests": tests_AuthenticationServiceCaptchaAdapterTests
            "AuthenticationServiceSignInErrorAdapterTests": tests_AuthenticationServiceSignInErrorAdapterTests
            "AuthenticationServiceSignInTemplateAdapterTests": tests_AuthenticationServiceSignInTemplateAdapterTests
            "AuthenticationServiceSignUpErrorResponseAdapterTests": tests_AuthenticationServiceSignUpErrorResponseAdapterTests
            "AuthenticationServiceSuccessResponseAdapterTests": tests_AuthenticationServiceSuccessResponseAdapterTests
            "AuthenticationServiceTests": tests_AuthenticationServiceTests
        }
    end function
    instance.getTestSuiteClassWithName = function(name)
        return m.testSuites[name]
    end function
    instance.getAllTestSuitesNames = function()
        return m.testSuites.keys()
    end function

Some notes:

  • In theory, this code should be faster to execute, as map lookups should be faster than arbitrary if checks in large collections.
  • This change should also allow for more suites to be included before the Roku compiler freaks out.
  • Because of m.testSuites.keys(), this change has the unintended side-effect of ensuring A-Z sorting of all test suites. I've made it less unintended by having the plugin sort the testSuitesToRun array.

@TwitchBronBron TwitchBronBron merged commit 10cb993 into rokucommunity:master Jul 1, 2024
4 checks passed
@luis-soares-sky luis-soares-sky deleted the fix/test-function-limit branch July 1, 2024 17:11
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.

3 participants