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

JS: Remove dead state transition validation code #1771

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

yuvipanda
Copy link
Collaborator

Soooo, because this.state was initialised to null and not 'start', this code was always actually dead.
validateStateTransition had no branch for oldState being null, so always returned false. This meant this.state was never set to current state, and so in all callbacks, oldState was always null!

I validated this again by console.logging oldState and newState inside validateStateTransition. Here's the output for when a full build is performed:

null -> waiting
null -> fetching
null -> unknown
null -> building
null -> failed
null -> built
null -> launching

And for when launching a previously built image

null -> launching
null -> ready

I also put one just above where this.state is set, and that code was never called.

I was hoping to remove all this code anyway, as it doesn't actually validate nor test anything - that's really done by unit tests and integration tests. I thought this would hide bugs - but turns out, it was a bug itself, and hid nothing.

This also changes the signature of the callback for onChangeState, dropping oldState and newState. oldState was always null, and in our code, we actually don't use newState at all. The one place that was conditional on oldState being null is now unconditional, because oldState was always null.

Ref #774

Soooo, because `this.state` was initialised to `null` and
not 'start', this code was always actually dead.
`validateStateTransition` had no branch for `oldState` being
null, so always returned `false`. This meant `this.state`
was *never* set to current state, and so in all callbacks,
`oldState` was always `null`!

I validated this again by console.logging `oldState` and
`newState` inside `validateStateTransition`. Here's the output
for when a full build is performed:

```
null -> waiting
null -> fetching
null -> unknown
null -> building
null -> failed
null -> built
null -> launching
```

And for when launching a previously built image
```
null -> launching
null -> ready
```

I also put one just above where `this.state` is set, and that
code was never called.

I was hoping to remove all this code anyway, as it doesn't
actually validate nor test anything - that's really done by
unit tests and integration tests. I thought this would hide
bugs - but turns out, it was a bug itself, and hid nothing.

This also changes the signature of the callback for
`onChangeState`, dropping `oldState` and `newState`. `oldState`
was always `null`, and in our code, we actually don't use
`newState` *at all*. The one place that was conditional on
`oldState` being null is now unconditional, because `oldState`
was always `null`.

Ref jupyterhub#774
@yuvipanda
Copy link
Collaborator Author

This is one way to get to 100% unit test coverage - just find code that was never used and get rid of it :)

@consideRatio consideRatio added maintenance Under the hood improvements and fixes code:html/js/css html/js/css changes. code:js-binderhub-client js changes to binderhub-client labels Oct 9, 2023
@consideRatio consideRatio merged commit a769bc1 into jupyterhub:main Oct 9, 2023
11 of 13 checks passed
@consideRatio
Copy link
Member

Wieee thank you for working this @yuvipanda!

consideRatio pushed a commit to jupyterhub/helm-chart that referenced this pull request Oct 9, 2023
}
image.onStateChange('built', function() {
$('#phase-already-built').removeClass('hidden');
$('#phase-launching').removeClass('hidden');
$('#phase-launching').removeClass('hidden');
Copy link
Member

Choose a reason for hiding this comment

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

This line is a duplicate

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for revieiwng @manics! I opened #1772 as I was too quick on the ball

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code:html/js/css html/js/css changes. code:js-binderhub-client js changes to binderhub-client maintenance Under the hood improvements and fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants