73 points · by sam345 · 5y ago · 82 comments
These CD advocates seem to be saying that you can take human out of the testing equation and rely solely on automation. I just don't buy it.
I haven't seen true continuous delivery in the wild and I'm starting to think this is just the empty promises of a club of consultants who peddle their wares to unsuspecting VPs. Tell me what I'm missing.
Personally, I find unit tests to be mostly useless. Every time I touch code with a unit test, I also need to change the unit test. Rather than testing, it feels like writing the same code twice.
I think they're mostly useless when refactoring, but they're useful when writing new code and and making relatively small to medium sized changes. For new code, it's helpful to me at least to express my intentions in a more concrete form and it gives me more confidence that I didn't miss something. For making relatively small changes, they help catch fined-gained regressions. Even if I meant to make a change, a failing test forces me to think about handling a particular case correctly that I might have forgotten.
The kind of unit test I do hate are the ones that are so mock-heavy that they're pretty much only testing the structure of your codebase (did you call all the methods the right order and nothing more?). I was once on a team where that was pretty much all they wrote, and they were very resistant to any level of integration unit testing because (I think) they read in a opinionated book somewhere that low level tests were good enough (they weren't).
.
1. Unit tests. But I only write them for stuff that needs them.. Eg. Some complex math functions that translate between coordinate systems; the point of the unit tests is to confirm that the functions are doing exactly what I think they are doing. With mathsy stuff it can be very easy to look at the output of some function and think, that looks fine, but in reality its actually slightly off, and not exactly what it should be. The unit tests are to confirm that its really doing what I think its doing.
.
2.Acceptance tests by a human. Theres a spreadsheet of everything you can do in the game and what should happen. Eg. press this button -> door should open.. As we add features we add more stuff to this list. At regular intervals and before any release several humans try every test on various hardware. This is to catch big / complex bugs and regressions. Its super tedious but it has to be done imo. Automating this would be an insane amount of work and also pointless as we are also testing the hardware, you get weird problems with certain GPUs, gamepads, weird smartphones etc.
.
I find those two types of tests to be essential, the bare minimum. But also anything in between, like some kind of automated integration testing is just a shittone of work and will only be useful for a relatively brief period of development, changes will quickly render those sort of tests useless.
I think the issue with them lies in that most developers aren't shipping libraries, they're shipping integrated systems, so there's no component worth testing. (you can always invent one, but that's just overcomplicating the code).
At the same time, it's also genuinely hard to write good, principled tests of integrated systems, harder than it is to code up a thing that kinda-works and then manually debugging it enough to ship. You have to have the system set up to be tested, and feature complexity actively resists this - you fight a losing battle against "YOLO code" that gets the effect at the expense of going around the test paradigm.
That is a very normal setup.
> Worse, they'll start to become unreliable due to the number of operations being performed. So you'll end up with a test suite that takes potentially multiple hours to run, and may periodically fail just because.
This is called flakiness and is generally a symptom not to be ignored, as it is almost always indicative of bigger issues. It's rare that flakiness is limited to test environments. Instead it's much more likely that whatever your smoke tests are experiencing is a something end-users are also intermittently hitting.
> The feedback loop becomes so slow that it's not helpful during actual coding.
Devs can write their own unit tests when working on their assigned tasks. Smoke tests are designed to run when you're trying to integrate those changes into the existing codebase. At that point, you have the calculus all wrong. Smoke tests slow down devs enough that they don't merge broken code into production. That is a useful release gate unto itself.
If unit tests pass but smoke tests fail, then often (the vast majority of the time in my experience) the issue is that either the dev didn't understand the task or, more often, didn't understand the system they were integrating into.
If you have some code that if its callers changed you would want to change it too, then it's on the same unit as the calling code, and it's bad to divide it away.
Our test suite includes some unit and full end to end tests, and yea sometimes a breaking change slips through, we write a test to catch it next time, and move on.
(Though our deploy process involves spinning up new instances to run our code, and our load balance won’t switch over to new boxes if they return 500s, so fully broken deploys don’t actually get hit by customers.)
Different projects have different complexities and differing levels of CD viability, but there are definitely many people truly doing automated continuous deployment all day every day.
Besides less-anemic E2E tests, this is why type systems exist.
Define a well-typed interface, code to the interface, test the units — and then it's hard to make terrible mistakes wiring things up. To realize the full benefit does, of course, require substantially better data structures than string-to-Any hashes, and it requires some proper old-school software engineering (i.e. injecting a client as an argument and not just mocking out the someOtherClient.client() method.) And there is some overhead, though I'd say that a proper null-checking pass alone would be worth that much. (Sorry, Java, your types are terrible.)
My last two jobs have had what I understand to be continuous delivery, to great success, but perhaps it was something other than CD.
but functional programming makes unit tests the natural way to regression-test the top 80 to 90 percent of your codebase, and those don't have to target tiny pieces - they can target large units.
In all, I’d say the pain of feature branches and PRs is tiny compared to trunk based development, even for teams as small as two.
It’s not the industry standard without reason.
That doesn't mean an entire feature has to go in one commit (usually). Often a feature is made up of a series of non-breaking changes that can be layered one at a time, if appropriate.
Edit: Rereading your comment, I suspect you mean non-local backups. Our organization has a special remote only visible to you and those you allow for pushing code you'd like to backup off of your box.
Another thing that can help is a source control system that supports multiple commits and committing them to the main branch as a contiguous unit. I believe Phabricator supports that.
The next best thing you can do with GitHub is make your pretty series of commits for review, but then squash on completion using the GitHub UI. GitHub retains the individual commits of the PR that we’re reviewed while the main branch history has a single commit that passed CI.
You can theoretically guard against that with more and more automated testing, but that's putting a lot of weight on a thing that's almost always full of things you forgot to test, or didn't think you needed to test.
I've had better luck with feature flags. They don't take anything away from automated tests or static analysis. They potentially add a little bit more hassle in the form of maintaining the flags. (Not nearly as much hassle as sorting out a merge conflict, though.) The other, quite compelling, thing they add is a much wider expanse of time during which you can notice, "Huh, that's funny," when you're doing your mid-development ad-hoc testing.
You can, of course, get a similar benefit by making a daily practice of rebasing your feature branch onto the latest version of the main branch. But my experience has been that doing that is annoying, and the thing about annoying things that you have to actively remember to do is that it's surprisingly easy to just not remember to do them.
Feature flags make functional overlap and branching explicit and prevent difficult merge conflicts. They're easier for humans to reason about, and far easier/safer to do percentage rollouts with.
This author has much to teach us about evil after all
I have no idea whose blog I'm reading here, but he doesn't exactly sound like someone whose opinion on version control and branching strategies should count for very much.
Coming next week - a post about why X is the best programming language, from someone who hasn't bothered to learn any other programming languages!
By simple workflow I mean the simple workflow that mimmicks what you would've done with SVN (or CVS for that matter). Remember the holy wars of SVN over CVS? "What do you mean the entire repo has one version number instead of each file? Are you insane!" :)
What git allows for are different workflows and some of them are probably harder to understand than others but very workable ones are really easy too and don't require a host of commands or a deep understanding as long as simple rules are followed. All of my last few new hires (juniors) can work without problems with our simple git workflow. FWIW, we use short lived branches per ticket that get PR'd into master. Master is always green and deployable (hourly). The branch is yours to do with whatever you want until you want to actually merge to master, at which point you have to squash and rebase from master.
Some guys got bitten by not following the simple rules of "do one thing at a time" and "commit first". Luckily git refuses many actions if you have a dirty tree but people can get confused because they never read error messages. "Yes, yes I pulled and then ... and now it doesn't do what it's supposed to". Do one thing at a time works for most things in life and software development and rebasing from master while also squashing at the same time is just insane. Just do one of them first. Usually I find squashing first is easier as otherwise you might have to solve conflicts on intermediary commits that you wouldn't have in the first place with your squashed commit.
Sure, they don't all know the ins and outs of the git data model and what every command does. But I've never seen anyone that couldn't understand git pull, git commit, and git push. If the org uses a branching model, you can teach them git checkout -b, git checkout <branch_name>, and git merge origin/master to switch between branches in 5 minutes. They might get themselves into trouble eventually, but then someone more experienced can come by with git reflog and help them recover their work. Set up their github project to use squash commits only so each PR is one commit and master is always linear and they're off to the races.
Despite some command naming quirks, the simple stuff is pretty simple in git and the more advanced stuff is there when you want to learn it. I really don't buy that there is any good reason to choose SVN these days, regardless of how junior the team might be.
Hey, that was me-- wasn't that all of us, after we learned our first programming language?
This puts the burden of branch maintenance/compatibility on the branch owner, and allows a clean and clear place for code review.
Using Trunk-based development with feature flags seems to be me to be the best way of ensuring success with a Pull Request model.
Google has a monorepo and what could describe as 'submit patch for code review'. Only certain engineers can approve reviews and trigger the patch being applied to the trunk.
https://github.com/google/eng-practices
Many of the others also have variations, but unlikely that any organisation with 1000+ engineers has a monorepo with all of those engineers directly committing to it.
This alone doesn't tell me anything about their process. It happens with unbranched workflows as well (unless you use a VCS that prevents more than one person from checking out a file at one time). The fact is, some work takes a few days (or weeks) to get right, and in the meantime other people may have changed those files. This is why `svn update` and `p4 sync` exist.
I have worked on many teams that did continuous integration, but never continuous deployment. With continuous deployment, say I branch off trunk and start to implement FeatureA. Just after that, someone else branches off trunk, implements a smaller FeatureB, and merges it back in to trunk. The next day I finish FeatureA and open a pull request back to trunk.
All unit tests pass on the code I submitted, and there are no conflicts with trunk. But still, it's not going to be a fast forward merge, so the code I submitted is different than what will be actually be deployed after FeatureA is merged to trunk. And maybe after merge, certain unit tests will fail on trunk. This same truth applies regardless if my pull request is set to squash-merge or rebase.
So my question. When do unit tests automatically get run?
1. On my feature branch after the pull request is opened?
2. On trunk after my feature branch is merged?
3. Both 1 and 2?
4. Or am I, as a submitter of code required to continually update my pull requests such that they are always going to be fast forward? That is, if I am waiting on a pull request to be merged, and someone else's PR is merged do I have to rebase my code on top of trunk every time?
|
|\
|\\
|||FeatureB
|//
|/
* Passing unit tests in FeatureB do not guarantee passing unit tests hereSo the trick is to figure out where (which side) you are and will be and utilise the right strategy.
- CI requires an automation tool to run a test suite. If you don't have one yet, you need to set one up (and, you know, have a suite of tests to run). hand-waves the idea that the test suite is perfect
- If you don't have Pull Requests to gate the test suite before merge to trunk, the tests have to be done pre-merge. But that means it has to run on your laptop, and maybe there's too many tests. So you can do 'fake' Pull Requests, by keeping a CI server with one copy of your repo, and if the tests pass, pushing that copy or change to the 'real' repo.
- Even if you do have Pull Requests, or Fake Pull Requests, and a person has to approve them before merge (a good idea), you can still end up with a PR stuck in pending-approval state for eternity. And every time a change hits the trunk, the PR needs to be rebased, retested, and possibly bugs fixed. This means the equivalent of a branch being open for a long time - the whole reason not to use feature branches.
- Therefore, assuming you have a test suite, and a CI server, you must only merge very small changes, quickly. Not only must the change be small, you must have review & approval constantly. Or throw out the review/approval step. Or only do it once a day, which goes back towards the long-lived branches that we're trying to avoid.
- Of course with all this fast merging, it's increasingly likely you will introduce a bug, because no testing is perfect. So you have to also back out changes quickly. But you still won't always catch them quickly.
- With all these changes and reverts happening all the time, the trunk is constantly changing underneath everybody. So you have to rebase or merge constantly. If you don't, it will take you longer to refactor the changes you've just developed to work with the new changes.
- And since you can't possibly implement a complex new feature at once with only small commits, you have to use feature flags and other strategies to keep your untested new code from exploding until you think it's ready for prime time.
- As all of that is going on, you also of course need to test all this crap. So you'll need a CD system designed to constantly deploy to various environments, potentially managing many constantly changing dependencies and data sets depending on what's being pushed/tested.
- That system has at least the same complexity as the CI system, but it's infrastructure-heavy, which means you'll need to lean heavily on DevOps practices and SWE having the tools and training to manage their own deploys/infra. And we haven't even talked about versioning.
These are just some of the issues that some books cover (I think) but quaint blog posts about branching never mention. How long will it take your team(s) to implement all of that and completely change their SDLC?
s/\([Ee]vil\)ness/\1/g
The noun form of "evil" is "evil".For an analogous example, try replacing "lightness" with "light" in a discussion about color and see how much sense the text makes afterwards.
Yeah, that'll get really weird really fast, what with "lightness" being about weight and not colour, and all...
Can't even complain that it's a neologism and kids these days with their bad grammar; "yfelnyss" would appear to predate the Normans.
Nor is "evil" in the noun sense a great synonym for "evilness" in the noun sense. "Evilness" denotes the state of being bad, while "evil" denotes the badness itself. Evilness is the correct word here. Using "evil" would have been, if we want to be really pedantic (I hope I can safely assume that we do), been mildly nonsensical.
[EDIT:] However, I can't agree that TFA is about "the state" of feature branching, or really even that feature branching is an entity that can possess a state. According to TFA, feature branching is bad. That's an intrinsic property, not one that feature branching will be able to overcome with appropriate prayer and reflection.
This is usually the case when abstract nouns are considered evil, so "evilness" is usually poor diction.
Indeed, we could not say "the black of feature branches"; it would have to be "blackness". Something that is black (adjective-wise) doesn't "have black" (the noun); it "has blackness".
The word "evil" doesn't conform to this restriction; "the evil of feature branches" is fine. Therefore "evilness" is just superfluousnessitude.
The word "bad" is color-like. We need "the badness of feature branches", not "the bad of feature branches".
But "evil" functions in such a way that it can substitute for "badness", and therefore for "evilness".
When we say "the evil of feature branches", the grammar is very similar to "the hypocrisy of using feature branches" or "the iniquity of using feature branches" or "the stink of feature branches" and such.
None of these words require an additional suffix; "stink" need not be worked into "stinkiness".