1
1
[[chapter_23_debugging_prod]]
2
- == Debugging And Testing Production Issues
2
+ == Debugging And Testing Server Issues
3
3
4
4
.A Note for Early Release Readers
5
5
****
@@ -28,25 +28,6 @@ Ah yes, we had just built a way of pre-authenticating a user.
28
28
Let's see how that works against Docker and our staging server.
29
29
30
30
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
-
50
31
51
32
=== The Proof Is in the Pudding: Using Docker to Catch Final Bugs
52
33
@@ -1089,11 +1070,13 @@ $ pass:quotes[*TEST_SERVER=localhost:8888 python src/manage.py test functional_t
1089
1070
OK
1090
1071
----
1091
1072
1092
- // DAVID: Shall we do a git commit?
1073
+ Probably a good time for a commit :)
1074
+
1093
1075
1094
1076
[role="pagebreak-before less_space"]
1095
1077
.Warning: Be Careful Not to Run Test Code Against the Production Server!
1096
1078
*******************************************************************************
1079
+
1097
1080
((("database testing", "safeguarding production databases")))
1098
1081
((("production databases")))
1099
1082
We're into dangerous territory,
@@ -1103,53 +1086,57 @@ that you don't accidentally blow away your production database
1103
1086
by running FTs against the wrong host.
1104
1087
1105
1088
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 ,
1107
1090
and make it so they use different keypairs for authentication, with different passphrases.
1108
1091
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.
1110
1094
1111
1095
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.
1114
1098
1115
1099
*******************************************************************************
1116
1100
1117
1101
1118
1102
=== Wrap-Up
1119
1103
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.
1124
1108
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.
1129
1114
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
1132
1118
the ability to save their lists on a "My Lists" page.
1133
1119
1134
1120
1135
1121
.Lessons Learned Catching Bugs in Staging
1136
1122
*******************************************************************************
1137
1123
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
+
1138
1130
Fixtures also have to work remotely::
1139
1131
`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.
1144
1137
((("fixtures", "staging and")))
1145
1138
((("staging sites", "fixtures and")))
1146
1139
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
-
1153
1140
Be very careful when resetting data on your servers::
1154
1141
A command that can remotely wipe the entire database on one of your
1155
1142
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::
1159
1146
1160
1147
Logging is critical to debugging issues on the server::
1161
1148
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.
1165
1153
((("logging")))
1166
1154
((("debugging", "server-side", "baking in logging code")))
1167
1155
0 commit comments