Skip to content

Commit 97d0fce

Browse files
committed
Finished pass thru 23
1 parent 52d4216 commit 97d0fce

File tree

2 files changed

+38
-49
lines changed

2 files changed

+38
-49
lines changed

chapter_20_mocking_1.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ Something like this:
797797
798798
{% if messages %}
799799
<div class="row">
800-
<div class="col-md-8">
800+
<div class="col-md-12">
801801
{% for message in messages %}
802802
{% if message.level_tag == 'success' %}
803803
<div class="alert alert-success">{{ message }}</div>
@@ -811,6 +811,7 @@ Something like this:
811811
----
812812
====
813813

814+
// TODO: feed thru change
814815

815816
Now do we get a little further? Yes!
816817

chapter_23_debugging_prod.asciidoc

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[[chapter_23_debugging_prod]]
2-
== Debugging And Testing Production Issues
2+
== Debugging And Testing Server Issues
33

44
.A Note for Early Release Readers
55
****
@@ -28,25 +28,6 @@ Ah yes, we had just built a way of pre-authenticating a user.
2828
Let's see how that works against Docker and our staging server.
2929

3030

31-
////
32-
SEBASTIAN:
33-
It's worth reiterating the testing strategy in the real world. The chapter is
34-
called "Debugging And Testing Production Issues" yet it focuses on running
35-
tests against another non-production environment. It uses methods which I find
36-
a bit controversial because they don't treat the staging environment as a black
37-
box.
38-
39-
40-
DAVID:
41-
Nice one. I particularly liked the discussion of when to choose not to test
42-
something, in this case email.
43-
44-
I do think we should talk a little more about security here - readers should
45-
adopt a security mindset when doing things like this and make sure they think
46-
things through.
47-
////
48-
49-
5031

5132
=== The Proof Is in the Pudding: Using Docker to Catch Final Bugs
5233

@@ -1089,11 +1070,13 @@ $ pass:quotes[*TEST_SERVER=localhost:8888 python src/manage.py test functional_t
10891070
OK
10901071
----
10911072
1092-
// DAVID: Shall we do a git commit?
1073+
Probably a good time for a commit :)
1074+
10931075
10941076
[role="pagebreak-before less_space"]
10951077
.Warning: Be Careful Not to Run Test Code Against the Production Server!
10961078
*******************************************************************************
1079+
10971080
((("database testing", "safeguarding production databases")))
10981081
((("production databases")))
10991082
We're into dangerous territory,
@@ -1103,53 +1086,57 @@ that you don't accidentally blow away your production database
11031086
by running FTs against the wrong host.
11041087
11051088
You might consider putting some safeguards in place at this point.
1106-
For example, you could put staging and production on different servers,
1089+
You almost definitely want to put staging and production on different servers, for example,
11071090
and make it so they use different keypairs for authentication, with different passphrases.
11081091
1109-
// DAVID: Or maybe something simpler like quitting if the host isn't in an allow-list?
1092+
I also mentioned not including the FT management commands in INSTALLED_APPS
1093+
for production environments.
11101094
11111095
This is similarly dangerous territory to running tests against clones of production data.
1112-
I have a little story about accidentally sending thousands of duplicate invoices to clients
1113-
in <<data-migrations-appendix>>. LFMF!
1096+
I could tell you a little story about accidentally sending thousands of
1097+
duplicate invoices to clients for example. LFMF! And tread carefully.
11141098
11151099
*******************************************************************************
11161100
11171101
11181102
=== Wrap-Up
11191103
1120-
Actually getting your new code up and running on a server always tends to
1121-
flush out some last-minute bugs and unexpected issues. We had to do a bit
1122-
of work to get through them, but we've ended up with several useful things
1123-
as a result.
1104+
Actually getting your new code up and running on a server
1105+
always tends to flush out some last-minute bugs and unexpected issues.
1106+
We had to do a bit of work to get through them,
1107+
but we've ended up with several useful things as a result.
11241108
1125-
We now have a lovely generic `wait` decorator which will be a nice Pythonic
1126-
helper for our FTs from now on. We have test fixtures that work both
1127-
locally and on the server, including the ability to test "real" email
1128-
integration. And we've got some more robust logging configuration.
1109+
We now have a lovely generic `wait` decorator
1110+
which will be a nice Pythonic helper for our FTs from now on.
1111+
We've got some more robust logging configuration.
1112+
We have test fixtures that work both locally and on the server,
1113+
and we've come out with a pragmatic approach to testing email integration.
11291114
1130-
But before we can deploy our actual live site, we'd better actually give the
1131-
users what they wanted--the next chapter describes how to give them
1115+
But before we can deploy our actual production site,
1116+
we'd better actually give the users what they wanted--the
1117+
next chapter describes how to give them
11321118
the ability to save their lists on a "My Lists" page.
11331119
11341120
11351121
.Lessons Learned Catching Bugs in Staging
11361122
*******************************************************************************
11371123
1124+
It's nice to be able to repro things locally::
1125+
The effort we put into adapting our app to use Docker is paying off.
1126+
We discovered an issue in staging, and were able to reproduce it locally.
1127+
That gives us the ability to experiment and get feedback much quicker,
1128+
than trying to do experiments on the server itself.
1129+
11381130
Fixtures also have to work remotely::
11391131
`LiveServerTestCase` makes it easy to interact with the test database
1140-
using the Django ORM for tests running locally. Interacting with the
1141-
database inside Docker is not so straightforward. One solution
1142-
is `docker exec` and Django management commands, as I've shown, but you should
1143-
explore what works for you--SSH tunnels, for example.
1132+
using the Django ORM for tests running locally.
1133+
Interacting with the database inside Docker is not so straightforward.
1134+
One solution is `docker exec` and Django management commands,
1135+
as I've shown, but you should explore what works for you--connecting
1136+
directly to the DB over SSH tunnels, for example.
11441137
((("fixtures", "staging and")))
11451138
((("staging sites", "fixtures and")))
11461139
1147-
// SEBASTIAN: I am wondering how strongly this approach should be recommended.
1148-
// In my mind, when one tests a service remotely, it would be a black-box testing
1149-
// without SSH-ing into it. The chapter is called "debugging prod", though.
1150-
// Then this is about debugging prod-like issues on staging?
1151-
// Some reiteration or additional context in diagrams could help.
1152-
11531140
Be very careful when resetting data on your servers::
11541141
A command that can remotely wipe the entire database on one of your
11551142
servers is a dangerous weapon, and you want to be really, really sure
@@ -1159,9 +1146,10 @@ Be very careful when resetting data on your servers::
11591146
11601147
Logging is critical to debugging issues on the server::
11611148
At the very least, you'll want to be able to see any error messages
1162-
that are being generated by the server. For thornier bugs, you'll also
1163-
want to be able to do the occasional "debug print", and see it end up
1164-
in a file somewhere.
1149+
that are being generated by the server.
1150+
For thornier bugs,
1151+
you'll also want to be able to do the occasional "debug print",
1152+
and see it end up in a file somewhere.
11651153
((("logging")))
11661154
((("debugging", "server-side", "baking in logging code")))
11671155

0 commit comments

Comments
 (0)