-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Better auto increment asset-tags [FD-32892] #13301
Conversation
PR Summary
|
This looks fantastic, @uberbrady - I need to test a bit more, but so far it looks excellent. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple small comments but 🎉 tests! 😄
|
||
public function testPrefixlessAutoincrementBackfill() | ||
{ | ||
// TODO: COPYPASTA FROM above, is there a way to still run this test but not have it be so duplicative? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One option for reducing duplication is PHPUnit's Data Providers since only the first line of these tests are different.
Here is an example in our codebase and a really good resource on getting started with Data Providers and a gotcha to look out for (see the Caveat
section).
In this case though...I would just keep the duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, agreed. I don't like that data provider thing at all, it gives me all of the Oogs. Every single one of them. I think just accepting the repetition is the move.
} | ||
|
||
$logAction = new Actionlog(); | ||
$logAction->item_type = Asset::class; | ||
$logAction->item_type = Asset::class; // can we instead say $logAction->item = $asset ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried it and it works 👍🏾 up to you if you want to include it in this chunk of work or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it ought to go in a different PR entirely, tbh. It's just a comment that I wanted recorded for posterity, so that we hopefully fix it at some point later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree 😄
|
||
public function testUnzerofilledPrefixlessAutoincrementBackfill() | ||
{ | ||
// TODO: COPYPASTA FROM above (AGAIN), is there a way to still run this test but not have it be so duplicative? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the TODO
s in this file so they don't end up confusing anyone in the future 👍🏾
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide that this is the right way (and it's seeming like we are deciding that), then I will leave the comment in just to keep people aware that changes to one spot might need to be copied to the others - but I would pull the TODO
tag so we don't think that we need to actually do anything about it.
$asset->asset_tag = $request->get('asset_tag', Asset::autoincrement_asset()); //yup, problem :/ | ||
// NO IT IS NOT!!! This is never firing; we SHOW the asset_tag you're going to get, so it *will* be filled in! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got confused by these comments. If I'm reading this right we can remove both comments right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to record, for posterity, how, exactly this system is actually working, rather than "how we think it might work" so that the next time someone has to look at this problem, they don't go through the same mental gymnastics realizing how it really works versus how we think it might want to work.
Very happy to workshop a better way of conveying this to future-us (who are going to look at this again in, like, a few months or years or something...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha. I was thinking these were debug comments for yourself as you worked through this PR. Keeping them there works for me 👍🏾
Before, it was possible to 'mess up' the auto-incrementing asset tags by bumping the suggested asset tag up by one - then, forever after, each 'suggested' new asset tag would conflict with one already in the system, until you finally go into the asset tag settings and manually bump up the "Next auto-increment" setting by one.
Now, we try to be intelligent and set the next auto-increment value to the currently-just-created asset's asset_tag, plus one, IF AND ONLY IF the currently created asset has a higher value than the next.
Additionally, I've added tests to confirm that various failure scenarios in asset-tag generation no longer happen.
I unfortunately fixed the problem before I added the tests, but I just back-ported the tests only to the existing code-base, and I ran them, and got this lovely output (proving that the tests do break on our current code, but are fixed on my new code. Which is want you want :) )
FAIL Tests\Unit\AssetTest
✓ auto increment
✓ auto increment collision
⨯ auto increment double
⨯ auto increment gap and backfill
⨯ prefixless autoincrement backfill
⨯ unzerofilled prefixless autoincrement backfill
✓ warranty expires attribute