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

Prevent re-creating session file on end #65

Merged

Conversation

blueo
Copy link
Collaborator

@blueo blueo commented Mar 12, 2019

saveState will re-create a session file after the test session has ended. This adds a condition to check if the test session has been cleared before writing the file.

Copy link
Contributor

@dnsl48 dnsl48 left a comment

Choose a reason for hiding this comment

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

feels like it might be better to perform that kind of checks outside this method so we keep it simple and its semantics reflect its name and concern

@blueo
Copy link
Collaborator Author

blueo commented Mar 14, 2019

feels like it might be better to perform that kind of checks outside this method so we keep it simple and its semantics reflect its name and concern

Thanks @dnsl48, yeah I wasn't totally happy with this. What do you think of splitting the saveState out from applyState. So making applyState just return the newly modified state which is then passed to saveState for persistence. Would add another call to everywhere applyState is currently used but would allow checks before saving and might just be a bit cleaner.

@dnsl48
Copy link
Contributor

dnsl48 commented Mar 14, 2019

What do you think of splitting the saveState out from applyState

Sounds like a plan. I guess we don't really have a choice right? :)

@dnsl48
Copy link
Contributor

dnsl48 commented Mar 14, 2019

making applyState just return the newly modified state

it also feels weird that applyState actually modifies the state... Since you're looking into it anyway, could you please consider if we might refactor this too?

@blueo
Copy link
Collaborator Author

blueo commented Mar 14, 2019

making applyState just return the newly modified state

it also feels weird that applyState actually modifies the state... Since you're looking into it anyway, could you please consider if we might refactor this too?

I was thinkingapplyState will return a new copy of the state - not touching the 'original' state - is that what you mean?

@dnsl48
Copy link
Contributor

dnsl48 commented Mar 14, 2019

I was thinkingapplyState will return a new copy of the state

well, I was rather thinking about moving out of it any modifications performed on the state, so it would only connect to the database preliminarily created outside. So it would only "apply" and not actually "modify" $state anyhow

@chillu
Copy link
Member

chillu commented Apr 5, 2019

@blueo Do you agree with Serge, and can implement his suggestion?

@blueo
Copy link
Collaborator Author

blueo commented Apr 5, 2019

Hey @chillu i was looking into it but haven't quite managed to get all state change out. the biggest hurdle being that the test db name may change. But in general yes I agree and I'll be working on re-factoring it the next chance I get :)

@blueo blueo force-pushed the pulls/prevent-recreating-session-file branch from 787ab03 to 92a4de4 Compare May 5, 2019 23:00
@blueo
Copy link
Collaborator Author

blueo commented May 5, 2019

Hi @dnsl48 :) So that turned into a bit of a rabbit hole. I've refactored to separate our applyState and saveState. In the process I've actually addressed the other two PRs I have open #64 and #63 (as they'd need significant change also).

given it is quite a big change I've added some unit tests to try cover some basic scenarios - i don't think this is exaustive atm. I'm using this refactor on an internal project so will be able to beef up the tests a bit as I go. cc @chillu

@dnsl48
Copy link
Contributor

dnsl48 commented May 5, 2019

wow, that definitely looks cool! I'll have a play with it some time this week.

@dnsl48
Copy link
Contributor

dnsl48 commented May 13, 2019

Hey @blueo, sorry for delay. I've run it, but it breaks otherwise green tests on my local setup.
That's what I'm getting:

./vendor/bin/behat @framework                                                                                                             
Bootstrapping
Creating test session environment                                                                                                                                             
Temp Database: ss_tmpdb_1557720566_5399227
                                                                                       
@retry                                                                                 
Feature: Log in
  As an site owner               
  I want to access to the CMS to be secure
  So that only my team can make content changes
                                           
  Scenario: Bad login                                                 # vendor/silverstripe/admin/tests/behat/features/login.feature:7
    Given I log in with "[email protected]" and "badpassword"           # SilverStripe\BehatExtension\Context\LoginContext::stepILogInWith()
    │                                     
    ╳  Notice: Trying to get property of non-object in vendor/silverstripe/testsession/src/TestSessionEnvironment.php line 648
    │
    └─ @AfterStep # SilverStripe\Framework\Tests\Behaviour\FeatureContext::waitResponsesAfterStep()                                   
    Then I should see "The provided details don't seem to be correct" # SilverStripe\Framework\Tests\Behaviour\FeatureContext::assertPageContainsText()

I'll do some debugging later this week, but it seems like TestSessionState isn't being persisted properly anymore.

@blueo
Copy link
Collaborator Author

blueo commented May 13, 2019

ah thanks @dnsl48 I'll have a look, i should probably add some basic behat checks

@blueo blueo force-pushed the pulls/prevent-recreating-session-file branch from 92a4de4 to 0bdf049 Compare May 14, 2019 01:25
@blueo
Copy link
Collaborator Author

blueo commented May 14, 2019

Hey there, @dnsl48 yep, I missed creating the testsession. I also had a broken mailer setup, I've addressed both and added some test cases for it 👍 framework behat now runs green for me

@dnsl48
Copy link
Contributor

dnsl48 commented May 14, 2019

Nice! Do you mind resolving the conflict or rebasing the branch yet?

@blueo blueo force-pushed the pulls/prevent-recreating-session-file branch from 0bdf049 to b4a54a5 Compare May 14, 2019 02:00
@blueo
Copy link
Collaborator Author

blueo commented May 14, 2019

Nice! Do you mind resolving the conflict or rebasing the branch yet?

done :)

tests/unit/TestSessionControllerTest.php Outdated Show resolved Hide resolved
@dnsl48
Copy link
Contributor

dnsl48 commented May 14, 2019

I know that's not changed in the PR, but could we change it to
!is_subclass_of($mailer, Mailer::class)?

if (!class_exists($mailer) || !is_subclass_of($mailer, 'SilverStripe\\Control\\Email\\Mailer')) {

Copy link
Contributor

@dnsl48 dnsl48 left a comment

Choose a reason for hiding this comment

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

That's really good job!
Thank you for doing those tough refactoring bits and untying this knot!

Let's think if we could spare backwards compatibility or otherwise we could think on moving this changes to master (and potentially the next major version of the module).

src/TestSessionEnvironment.php Outdated Show resolved Hide resolved
src/TestSessionEnvironment.php Outdated Show resolved Hide resolved
src/TestSessionEnvironment.php Outdated Show resolved Hide resolved
src/TestSessionEnvironment.php Show resolved Hide resolved
src/TestSessionEnvironment.php Show resolved Hide resolved
@blueo blueo force-pushed the pulls/prevent-recreating-session-file branch from 4ce5506 to 2eee104 Compare May 14, 2019 21:29
@blueo blueo changed the base branch from 2 to master May 14, 2019 23:01
@blueo blueo force-pushed the pulls/prevent-recreating-session-file branch from 2eee104 to 0eb7fa4 Compare May 14, 2019 23:06
@dnsl48
Copy link
Contributor

dnsl48 commented May 17, 2019

Here's the fix for TestMailer - silverstripe/silverstripe-behat-extension#188
It should be merged after this PR gets merged.

Copy link
Contributor

@dnsl48 dnsl48 left a comment

Choose a reason for hiding this comment

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

good work 👍

P.S.
Tested locally on ss/installer (@framework and @cms). Though, also requires silverstripe/silverstripe-behat-extension#188

@dnsl48 dnsl48 removed their assignment May 17, 2019
`appyState` will now only read the test session data and update the
environment to relect that state. This is intended for things like
database connections and mailer classes. Actions that need to alter
state to apply it (eg creating a temp db) should be done in other
actions such as 'start'

`saveState` will only take an existing state object and persist it to a
file

Also addresses:

[Connect to test database on session load](silverstripe#63)
[Skip Temp DB creation if state has no database prop](silverstripe#64)
Prevent re-creating session file on end (original issue for this PR)
@blueo blueo force-pushed the pulls/prevent-recreating-session-file branch from a3f7b51 to 1d8f112 Compare May 17, 2019 03:46
@dnsl48
Copy link
Contributor

dnsl48 commented May 19, 2019

Good to merge when silverstripe/silverstripe-behat-extension#188 is merged

@blueo
Copy link
Collaborator Author

blueo commented Jun 20, 2019

@dnsl48 it feels like we might be able to merge/tag this before silverstripe/silverstripe-behat-extension#188 ? I'd be interested in doing a little more work on this module around assets etc but I'm worried this will become the never-ending-pr if I do...

@dnsl48
Copy link
Contributor

dnsl48 commented Jun 20, 2019

feels like we might be able to merge/tag this before silverstripe/silverstripe-behat-extension#188 ?

Sorry, no can do, without 188 it breaks email related tests. On the other hand, I'm quite certain this PR will be merged "as is", so if you base your other PRs on top of this one, you most likely won't even need to rebase

@blueo
Copy link
Collaborator Author

blueo commented Jun 20, 2019

but if this is a new major version - you don't need to use it until you want right? So the email related tests would still use the older version?

@dnsl48
Copy link
Contributor

dnsl48 commented Jun 20, 2019

That's right. I think you're right. We can deal with behat-extension separately.

@dnsl48 dnsl48 merged commit f7632a8 into silverstripe:master Jun 20, 2019
@blueo
Copy link
Collaborator Author

blueo commented Jun 20, 2019

cool thanks!

@blueo blueo deleted the pulls/prevent-recreating-session-file branch September 9, 2019 19:58
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.

4 participants