AWS RDS SqlServer Native Backup and Restore

Had to learn this yesterday to clone a production environment down to a lower environment. Figured it qualified for a blog post.

exec msdb.dbo.rds_backup_database 
         @source_db_name='xxxProd',
         @s3_arn_to_backup_to='arn:aws:s3:::xxx-sql-native-backup/xxxProd.bak',
         @overwrite_S3_backup_file=1,
         @type='full';

exec msdb.dbo.rds_task_status;   -- till lifecycle=SUCCESS

ALTER DATABASE xxxUAT SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
drop database xxxUAT;
exec msdb.dbo.rds_restore_database
         @restore_db_name='xxxUAT',
         @s3_arn_to_restore_from='arn:aws:s3:::xxx-sql-native-backup/xxxProd.bak';
exec msdb.dbo.rds_task_status;   -- till lifecycle=SUCCESS

delete from xxxUAT.dbo.SensitiveTableStuff;

The Gotcha’s were:

  • Had to set up an option group that added SqlServer Native Backup and Restore to the RDS instance.  It took a few minutes to apply, the RDS instance did not reboot or go offline during this process.
  • Could not restore over an existing database.
  • Learned the hard way that while you can detach, you can’t re-attach a database using SSMS.  Reattaching uses a custom stored procedure.   And detaching and attaching had nothing to do with deleting.

From Certifiable to Certified

imageYesterday, I passed my AWS Certified Developer Associate exam.  I started studying for it two weeks ago.

Actually, no, I started studying for it a year ago when I started using AWS.  And at the time, I thought I was going to take the Certified Solutions Architect Associate exam, but we went for this one because its easier, and I had two weeks to study for it.

Why two weeks?  My company has been going for an AWS Partnership thing, and for that we need two certs.  It wasn’t a immediate priority… until some stuff came up which really affected some of our value.   We raised the flag, this needs to be a priority.  Schedule it and take it, and lets send two people so that if either one passes, we’re good.   We both passed.

What did I learn in those two weeks about how to study for the exam?  If I were to go back in time to younger self, what would I tell him?

ACloud.Guru, but not like that

https://acloud.guru is VERY good.  I’m keeping my subscription to it so I can listen in to some of the master-level courses during my commute.   However, I had prescribed something like:

  1. Listen and watch all the videos
  2. Take all the Quizzes
  3. Take the practice exam
  4. Go read other boring stuff.

Inefficient and Fear Based

Turns out, if you get a subscription, they have this thing called an Exam simulator (beta).  And at the end of this you get to see what you did wrong (as well as what you did right), and an explanation of the thing, and a link to more resources:

image

The suggestion is to attack the problem from a different angle

Thing is, both the real exam and the practice exam asked some pretty in depth questions that the video instruction does not directly cover.  Ryan does say, “Make sure you read the FAQs” and that’s 100% for real.  You gotta read the FAQ’s.

However, the FAQ’s themselves reveal the core ideas central to the service you are reading about. As do the videos.  My suggestion is that once you are comfortable, you get denser information faster from the FAQ’s. 

I also found that the developer exam really wanted to know if you had used something.  Called some methods.   And if you hadn’t .. like me, I just barely used scan and query mostly I was being a sysop and using terraform to set things up for others ..  then reading through the actions, attributes, headers etc – gives you that feel of what actually working with the thing is like.  (Assuming you have plenty of experience and have done many things in the past).  You’ll get into the mind of the designers of the system, and from that, you can infer all kinds of stuff. 

Some Of My Notes

imageI started out taking notes on Paper.  Then I took notes in Google Docs. Then I switched over to sheets.

I’m a visual person, and I like organization, and having a big grid where to “store” information (human brain is optimized for location tracking) was very helpful for me.  If I got a concept wrong, I could go back to the place where that information was hiding on my sheet… it would probably help to have a background “image” to place information even better.  I’ll do that next time.

The Actual Exam

Here’s what was different from what I expected:  Location: Downtown Louisville, Jefferson Tech I think

  • Parking was easy to find early enough in the morning.  I vavigated straight to a parking lot, and paid for the day (less worry!), about 2 blocks away.
  • The proctors were very nice friendly people who gently guided my anxiety stricken self through what I needed to do.
  • Much to my surprise, I got there an hour early, and they invited me to take my test early. I was done by the time my actual start time came around.
  • The actual exam was pretty much at the same level of detail as the acloud.guru exam was, except for more “you really gotta know this” choose all that apply type questions.  I detected at least one stale question on the test, which I commented on.

My weakest areas:   Federation, and Cloud Formation, I think.   Makes sense, haven’t really had to do that, and we use Terraform for the same task.

Woot woot.  Okay, gotta go run a race now.

Visualizing Bitcoin Adventures

I’ve been riding a Bitcoin (and Ethereum) roller coaster for a year .. and its been a fun little diversion.   However, its hard to see the journey .. it feels like I’ve come out ahead, but have I really?

I doodled various (complicated) ways to try to show stuff via a 3D graph .. but when I actually went to play, this 2D version works just as well:

image

  • Vertical (down) drops ==  I transferred bitcoin (either to another account, or buying something with bitcoin).
  • To the top-left = I bought bitcoin for USD
  • To the bottom-right = I sold bitcoin for USD (for buying something usually)
  • Note: A similar chart would exist for my Ethereum account.  No, i did not buy a switch for $90, it was more than that.
  • Steep curve vs Shallow curve gives a feeling for price.   buy Steep, sell Shallow is the desire.
  • I could beat myself up .. if only I hadn’t spent the bitcoin, I’d have so much more now…
  • Currently, my experiment is net-positive.  Even if bitcoin goes to $0 right now.

How I created this

  • Download transaction report from Coinbase.   This is a .CSV file, which I then open in excel.
  • Their report has a “Amount” (Column C) which has + for bitcoin added, – for bitcoin removed.
  • Their report has a “Transfer Total” (Column H) .. but it isn’t signed. 
  • Their report also has a Transfer Fee column .. I’m ignoring that for this graph.    I did sum it up, I’ve paid $30 in fees this year.
  • Add a new column, “Signed Transfer Total”   formula is something like “=IF(H27<>0,H27*SIGN(-C27),0)” – to get a signed USD column.  Note that I’m reversing the sign so that a plus in bitcoin is a minus in USD.
  • Add a new column, “USD Balance”, which sums up all the Signed Transfer Total to date.   Something like “=SUM(J$6:J27)”.  For simplicity I added it right next to their bitcoin balance column
  • Grab those two columns and chart it, scatterplot, lines
  • Adjust the vertical size of the graph till you get something that works for you.  

In summary

I do not regret this Bitcoin experiment.

I do hope to leave stuff in Bitcoin, i think it will continue to grow for a while.

Learning New Stuff–Terraform, AWS, Lambda, DotNetCore

This last week has been a crash course in new stuff for me.  I’m helping with the scripts that manage the infrastructure around a project – freeing up the developer to work on user stories, I’m taking care (or trying to take care) of the deployment aspects of it.   In a way, its a big catch-up to other folks who have been charging ahead into newer technologies – so its not like I’m having to discover things on my own.  On the other hand, everything is already evolved to N+2, and I’m at N-1, so its a bit of a firehose.

Here goes though, stuff I’ve picked up this week:

  • Teamcity build calling a powershell script to do deployment stuff. 
    • New to me: I didn’t know PSPROJ was a thing – that I could step debug through powershell in Visual Studio now.  Come a long way since Powershell 1.0.
    • Dotnet lambda package, zipping, sending to S3…   Somebody else whose first name rhymes with “Miss” and last name rhymes with “Aye Lee” wrote this part for something else, I get to adapt it for the current project.
  • AWS API Gateway => AWS Lambda => C# NetCore1.0 => MVC  chain
    • Got to learn about the “Version Hell” that happens in NetCore1.0.   It will probably be much nicer by the time we get to 2.0 or better.. just the 1.0 to 1.1 is pretty rough at the moment.   Get the intersection of the bleeding edge of NetCore as it was 7 months ago with the bleeding edge of where AWS is taking their Amazon Linux.   We had to do a deviation and host some stuff via EB rather than Lambda. 
    • I’ll be playing more with this on Monday as I try to debug something into not giving me a 500 internal server error.
  • Terraform as a way of deploying AWS Resources
    • Modules, and Variables, and Data sources, oh my.
    • Debugging Terraform – I found the GET/POST requests.. the problem was a Content/Type for a resource in an S3 bucket.  Can’t get .body that way, so couldn’t get the hash value.
    • Partial apply’s because sometimes you don’t recognize a change and don’t want to mess up somebody else’s experimentation
    • I got to copy what Miss Aye Lee did, nice job Dude.
  • Rewrapping my brain around Build Configurations
    • Thanks to previous training, Build Config = Debug (PDB) vs Release, but also = XSLT Config Transforms to get configuration values per environment.
    • Now, Build Config = just Debug vs Release for “how debuggable do you want this”
    • There’s another avenue for “which settings do you want to use” which is completely different.
    • More playing with this on Monday.
  • AWS Security stuff
    • IAM User’s for local access from visual studio while developing
    • Roles for when running in Lambda, EC2, etc.  (Built by Terraform)
    • Policy documents describing what access available to what (built by Terraform), shared by the IAM and Role.
    • All the stuff that was actually built by Terraform using a Terraform runner credential
    • The Terraform Runner’s policy that allows it to create all the things
    • All running in another account that we cross-account assume roles into.
    • Somebody whose first name does not sound like XML and whose last name might have to do with Whiskey is a good teacher and dreamer.

The end result:

  • If starting from scratch – done by human.
    • cd env-shared;  terraform plan & apply to create shared resources, like S3 buckets, VPC’s, RDS’s, etc
    • Any further environment changes, also applied by human via script file.  No clicky the mouse.
  • New environment – like QA1 or QA2 or other – done by human
    • cd env-qa1 (or mkdir, if starting new)
    • copy and edit a file that says what the environment name is
    • terraform plan and apply to create all the things
      • DynamoDB tables
      • Queues
  • Every build to be deployed – automated, not done by human.
    • powershell to get stuff up to S3
    • powershell to call terraform to deploy
      • Lambda
      • API Gateway hangs out with this.

Pretty powerful stuff.     Glad I’m learning it.   It will feel better end of next week when I actually have something completely checked in that completely works.   

Tree of Direction == Claws of Doom

https://github.com/sunnywiz/TreeOfDirection/commit/8058bc3598c189ded425f044bde39528e335d4fd

This was supposed to look pretty, but its not.

image

If I look at the simpler version in an isometric top down view, it might make more sense:

image

This is taking a grid of points on a map, and asking Google for the optimal route from home to that point.  This ends up creating .. I don’t know what to call it.  Its a decision tree, says Lamont .. yes, that’s a good name for it.   It also points out that Google has forgotten that a certain street doesn’t go through, and is incorrectly routing me down Old Henry Rd.

I’ve added something in red .. its the boundaries between “neighborhoods”.    Also note that 3 routes almost touch where my current work is, which is why there’s so much indecision about the “best” route to work.  Whereas, if you’re in the middle of a particular neighborhood, then there’s little choice.   This says the best way for me to get to the new work place will be 146->HurstBourne.

I think this is better done staying as  a 2D print.   I might need to learn.. PdfKit?   Something to generate PDF’s with.  I can get a poster-sized PDF printed for $5 via Office Max.     However, what I might do is overlay a few maps .. like “with heavy traffic” vs “without”, with transparency.   And a lot more detail.

I did learn a lot about using Google’s Directions API.   Very nice.  Polylines are pretty amazing – took a small string and it decoded into 22 points!!!   https://developers.google.com/maps/documentation/utilities/polylinealgorithm.

More to follow, I’m sure.

Commute 3D print: 1/3: nodejs, openjscad, vscode

I have had a project in my brain for a long time – I think I first mentioned it in 2013*

The problem is, it wouldn’t go away.  It started to .. stink.  In my mind, stale, and stinking, and in my mind.   It had to be done.

The gist of the project is:

  • Take several ways of driving to work
  • Plot them out in 3D space with Time on the Z-Axis, in a virtual race as it were
  • Should be able to see things like stoplights show up as vertical bars

Well, I got tired of thinking about it, decided to do it.  I was spurred on by finding out that “jscad”, which I had known as openjscad.org, was now available as a node module — https://www.npmjs.com/package/jscad.  Okay, lets do this!

* Here’s a first reference: Car Stats: Boogers! Foiled!  1/11/2013  … There’s a few other posts just prior where I had been plotting interesting things from car track data, using powershell.

The implementation details

image

The above screenshot shows a sample output with some initial tracks, but .. they are the wrong tracks.  I’ll be recording the correct tracks later.

  • I created a “Base” for the sculpture by also drawing all the tracks along Z=0, but a little bit wider.
  • I made it a bit more stable by putting a “Pillar” up to the other end of the track, so its supported.

Code at: https://github.com/sunnywiz/commute3d .. the version as of 4/29/2017 11:57pm should be runnable to give the above output.

image

It took me probably 12 hours spread over 3 days …  here are some of the things I learned along the way:

chocolatey install nodejs

I’ve taken to using chocolatey to install windows packages so I don’t have to go hunt things down on the internet.   Most of my machines have it, its part of me setting up the machine.

I could totally install nodejs via chocolatey – and once installed, that gave me npm.

image

The command line, btw, would be:   cinst –y nodejs

npm init

This bit will seem silly to people who’ve been using it for a while, but these were the walls I had to hit.

image

Can’t npm install a package (everybody says “run this command” – it doesnt work) … until you’ve first “npm init” started a project.  I was thinking it was like CPAN where you added a package to a central repo and it was available, but nope, its more like “local depdency per project” more like nuget.  Makes sense, my CPAN (Perl) was was from 1998 and the world has changed since then.

node is awesome

It feels like the days of Perl way back.   Need something?  There’s a library.  Install it, use it, move on, solve the problem.  

VSCode is awesome

image

Editing and debugging is a LOT easier if you use an appropriate developer environment.  I tried vscode, and much to my surprise, I found it could:

  • Edit with intellisense (I knew this, but didn’t realize how fast it was)
  • Debug!  Watch!  Inspect!  OMG!   Very similar to Chrome Dev Tools.
  • Integrated terminal
  • Integrated git awareness and commits and pushes
  • Split screen yadda yadda
  • Very Nice.

nodejs asynchronous can be a learning curve

Take these two bits of code:

image

image

The first problem I had was that It would go to read all the tracks in … asynchronously.  I didn’t have a way to wait till all the tracks were read before it continued on to doing something with the tracks.

That lead me to some confusing code using “Promises.map”.  Then I found out that, most folks do const Promises = require(‘bluebird’)!    There’s a library that makes things easier.

So, if you’re not aware, and explaining to my future self:

  • Call readtracks .. its an async call
  • It returns a promise.
  • the implementation of readtracks eventually either calls resolve or reject (in my case, resolve).
  • At that point, the promise’s “then” clause gets run.
  • the glob … function (er, files)  is a “normal” nodejs callback strategy at the level below promises .. doesn’t rely on promises, its doing a directly specified callback.
  • the bluebird.map() basically does a foreach() on files, for each one, runs filename through a function, takes the result of that function, sticks it in an array.  It does this in a promise…
  • … which when its done with all the things, then calls resolve
  • the text fileName => readTrack(fileName) is the same as function(fileName) { return readTrack(fileName) }.
  • when you have promises, there’s a way of writing them out using “async” and “await”.    I didn’t try that.
  • the .then(resolve) is the same as .then(function( x ) { resolve(x); } )

The other beginner mistake that I kept making – I would forget to say “new” when I meant to create a new object.  Smile 

So I want to join two points in 3d space with a beam

I spent an embarrassingly long time trying to figure out how to take a cube, and scale it and rotate it and transform it so it acts as a beam between (x1,y1,z1) and (x2,y2,z2).

The answer is: 

image

The resolution:4 gives it four edges.

I need to view .STL files on my machine

3D Builder is a windows program that would let me do it, but it hung sometimes.

The easier route was to drag the model over to http://www.viewstl.com/  (which is what I did for the screenshot with this blog post).

Netfabb got Bought Out

Once upon a time, I found some really nice software .. which I thought I liked enough to give them real money.   Looking back, I cant find a record of giving them money… I guess I intended to at one point.

In the time that I haven’t been doing 3D printing, apparently AutoDesk bought them out, and.. the new cost is $125 PER MONTH.  Uh, no.   While researching for this blog post, I did manage to find a binary of the old netfabb Studio Basic, so I snagged that.   I saved my emails with the keys that I had used to activate it in the past, and those seemed to work, so Yay!

CSG Unioning of 1000+ things takes a long time

I also discovered console.time() while benching this.

When running the program, I end up with a bunch of CSG’s, but they’re all intersecting.  I need to merge them together to get a printable thing.

That code, when run for a larger print (100 tracks), took all of 18 hours to do the merging.  That was … too much.   So, I tried to write a program to make the merging easier.

1029 items (spheres, cylinders, boxes) unioned together, NO DEBUGGER, yielding a CSG with 11935 polygons:

  • If I union them in a for loop one after the other
    • 34 minutes!
    • It gets slower over time.
    • there’s a O(N^2) probably that happens under the hood – it has to re-consider the same shape over and over as it tries to add new shapes.
  • If I union them using a binary tree tactic:
    • 42 seconds!!!
  • The actual numbers:
    • image
  • There’s probably libraries out there that specializing in union arrays of CSGs, rather than two objects at a time.   Maybe I’ll upgrade at some point.

image

Note that if I upload the non-unioned version to somebody like sculpteo, they have an “auto-fixer” tool that fixes things pretty quickly, this is not absolutely necessary.  Just .. feels mathematically clean to do it.

I did try to write the above fancyUnion using promises, but .. didn’t help.  Node still only uses one thread, it did not branch out to multithreading. 

3 Major sources of Documentation for jscad / openjscad / csg:

Conclusion

Code is written!   

I’m going to hopefully get some tracks recorded over this week.

I’ll make another post of how the printing process goes with the real sculpture.

Inventory of Projects

I’ve been meaning, for a while, to put together a spreadsheet of the (software) projects I’ve worked on in my life so far.   The sheer number of them is staggering.

The thought was I could put in enough columns so that .. an interesting taxonomy could emerge. 

Its also one of those things where, I never thought the list would get so large that I couldn’t remember them, but.. here I am.  I guess 26 years of paid experience will do that to a person.

I Started It

I tried to do that for a bit – here’s what I got:

https://docs.google.com/spreadsheets/d/19ivowzqQJiPrMVk8rAfHbZ-cf_G6tqmQAzqYIW1sc00/edit#gid=0

image

The columns I have so far are:

  • Name
  • Year(s) – turns out some of them extended over multiple years.
  • Employed by + Project For – working at igNew, my project was for a client other than my employer.  But before that, these were the same.
  • Implementation Details – this was pretty hard, to figure out what columns to use:
    • Language – Its mostly C#, but if I go back far enough there’s some Java, Perl, Clipper, etc as well.
    • UI – technologies related to UI stuff
    • DB Backend – technologies related to database stuff
    • Host Platforms – I was trying to figure out how to say Asp.Net MVC vs a Windows Service.
    • Additional Technologies – I think maybe EF + Dapper need to move to DB column
  • Management Details
    • SCM used.. this feels like an unnecessary column, who would ever want this info?
    • Unit Testing / Mock framework – if sorted by start year, can see how this becomes important
    • Integration Testing – as I think this is super important, putting it out in its own column.
    • CI/Build strategy – or lack of it – how we went about running the project
  • Project Management Details
    • Roles
      • Engineer = “thought about how to do it” + “did it”
      • Lead Engineer = “mostly all me”
      • Project Manger = “updating the Burndown” + “Communicating estimates + schedule”
      • Ops Support = “things broke in Prod.  Figure it out.”
    • Slices  – If I worked with a team of people, then these are the bits that I worked on.
    • Proud Of – this is probably the best part of looking back.
    • Coworkers + Contacts – I’m going to have to go look up many names for Contacts.

What Now?

There are so many projects!   I put down 11 tonight,  I think the list of paid things is..  probably in the 40’s? 1-3 per year, depending on role, and then add in another 30-40 of fun things?

I guess I could make a list of all the projects I could think of first .. vertically .. going through each Job.

I could (and will!) also add in all the for-fun projects that I’ve done.  

But Why?

Simply put, this is to battle Imposter syndrome.   Also, in my job, I’m undergoing a role shift – where I’m taking on more Ops and Maintenance type work – it feels like a good time to look back at my career as a software developer and take some stock of what I’ve accomplished so far.

The other part of it is, … my resume.  I don’t need one at the moment, but every time people talk about keeping a resume updated … the level of detail involved … gives me anxiety.  So the thought is, if I have this spreadsheet out there – my resume can become more of “who I am” and “what I care about” and shove all the detail crap to this spreadsheet.

Updates to twit-sort

I am currently on vacation!  In Florida!  We drove!

I took the opportunity (in the early mornings / late nights when everybody else is asleep) to work on some code that I wanted to update – I don’t normally get time to do this.   Its my twitter-reading app.   Which only I use.  But hey, that’s fine, I haven’t tried to market it.

Changes

Change #1:  I kept seeing “…” with truncated tweets.  A little research led to some interesting stuff — basically following retweets to get down to the original tweet to get the text from there.

Along the way I tried to build up a “who quoted who” breadcrumb:

image

The code is a bit wonky:

image

However, its confusing – many people (or clients) retweet without actually having a retweet link.  There’s “quoting” which is different ..  eh. whatever.  If I’m given it via the API, passing it through, figure it out later.

Change #2: I surfaced the like count and favorite count, as well as a link per tweet to open the tweet in its own window (as hosted by twitter). 

image

Complications

I have the code in github, which is public, and I don’t want my access keys and tokens and stuff checked in there.   So, I had to fudge around a bit – this was my solution:

image

  • I created a branch with all the passwords and stuff, and worked from there.
  • Once it was done, I either did a rebase (with cherry picking) or a direct cherry pick to move commits over to master, which I pushed up.

Granted I could use my azure visual studio hosted git, but I wanted the code to be visible / usable.  So.. if anybody has other ideas of how to do this better, please let me know.

What Next (with this project)

Not much else I can do with this in its current codebase.  I could certainly make it prettier, but .. eh, that’s not me.

If I had unlimited time, I’d rewrite it – make it so it did all its fetching and filtering and sorting locally (in javascript).  I could get a LOT fancier then – things like pulling out hashtags into groups, etc.  Maybe adding some sentiment analysis things.

However, I have so many other projects on the burner.. this one won’t make it for a while.  My need has been solved, so there’s very itch here to scratch.

The url of the site:   http://twit-sort.azurewebsites.net

The code: https://github.com/sunnywiz/twit-sort

Making Educational Videos for Code Louisville

I volunteered to be a mentor for the latest session of CodeLouisville, on the .Net side.

No big deal, I thought.. and then, TreeHouse was unable to get their Entity Framework videos ready on time, so we, the mentors, volunteered to pick up the slack.

Naturally, I don’t do well when given an open ended problem, so I went into crazy-detail-mode.    I paid $15 for a 1-year subscription to https://screencast-o-matic.com/home  (VERY GOOD), and I started making videos.

And I ran out of steam.  Because, of course, I chose the slow, measured, one-thing-at-a-time approach, and I created far too much work for me to do myself.

Luckily, two other mentors suggested that we do X for our mentoring session – so if what I was doing was from top down, they were going bottom up.  Basically, show the fast way to create an MVC website, Code First, Scaffold, and let the students backtrack from there.

This worked VERY well.   It boot-kicked the students into effective land.  At least one of them showed me some working code in their project in the same week.

Lessons Learned

I am too. detail-oriented for my own good.

When in doubt, ask people what they need.

Sometimes, you just have to show the finished product and NOT explain everything, then go back and explain what is needed.   Its okay, people are resilient, they will survive Smile.

I like screencast-creation, but not more than a few hours a week: For a 20 minute screencast, it takes about 40 minutes of recording, about 2 hours of editing, another 20 minutes of rendering and uploading.   So basically plan on 4-5 hours for a 20 minute video on a topic.    Thus, I can probably sustain generating 10 minutes of educational content a week.

What Did I make

This is a walkthrough of LocalDB:   https://docs.google.com/document/d/1tTDKTQsfGPr_nFSbEifGQRc8dc-FfrxbPUfnc7CyKoc/edit?usp=sharing

This is a walkthrough of C# talking to SQL:  https://docs.google.com/document/d/1lSt-C5-L3VwLLGE6oJO3A_UOpIu2lYA-EWMhzAo-Ye0/edit?usp=sharing – it has links to 5 videos, and (eventually) links to code in github.

Unit Testing vs Integration Testing

Unit Testing

  • mock everything external to your code.
  • mock everything up to the thing to be tested
  • do some stuff
  • assert one thing.
  • Don’t continue a test – instead, mock up the environment to match the new thing to test, and write that in a new test, with a new assert.
  • Its cheap to run lots of tests
  • Its cheap to mock things.

Integration Testing

  • Its expensive to set up data
    • That’s a talk to itself, on how to do that in a sane repeatable way.
  • There is no mocking. Its real stuff, all the time.
  • Thus, when you achieve one milestone, your test (more like a “flow”) continues to the second milestone. Examples:
    • Upload, Pause, Continue Upload, Download, Pause, Continue Download
    • Upload, kill upload, Upload again
    • Upload, Download, kill Download, Download again.
    • Create item, edit item, rename/move item, delete item.
    • Its too expensive to try to get to a middle state, unlike mock-land.
  • Along the way, you print out “assessments” (to go with a AAA-style term) of where your test is at and what data its seeing.
    • ie, Arrange, and then
    • Act Assess Assert
    • Act Assess Assert
    • Act Assess Assert
  • In case of failure, you compare the log of the failed test with the log of a successful previous test to see what’s different.
  • The test can be VERY complicated – and LONG – and that’s fine. You only know the detail of the test while you are building it.
    • Once it goes green in a CI system, you forget the detail, until it fails.
    • If it does fail, you debug through the test to re-understand the test and inspect data along the way.
  • Expect flakiness
    • Sometimes things just fail. Example: locks placed on tables in PostGres for Unique in their UAT environment by some other process.
    • Sometimes things fail because of a reason
      • Somebody changed a schema.
      • Somebody deleted some key data
      • Some process crashed
      • Previous other test left behind data that FK locks the data you want to work with.
      • All these need human care and feeding and verification, its not “mathematically sound” like unit tests are.
    • Its a good idea to put an Assert.Ignore() if any failures happen during Arrange() section (ie, databases are down, file system full, etc – no longer a valid test. Not failed, but not valid, so ignored.
      • Can postpone this till a test starts to be flaky.
  • But when it works
    • you know that all the stuff is CORRECT in that environment.
    • And when it works in CI day after day after day, any failures = “somebody changed something unexpected” and needs to be looked at.
      • Fairly often its a shared DB, and somebody else changed schema in a way that you’re not yet accounting for.
      • Or somebody changed the defaults of something, and your test data that you’re hinging a test on has not been updated to match.

Which Ones To Use Where

  • Use Unit Tests to explore the boundaries and paths inherent in a piece of code.
    • Faster
    • Many of them
  • Use a single integration test (or just a few) to run through the code with all dependent systems
    • try to hit every SQL statement / external service at least once
    • If it worked, combined with all the unit tests, you’re probably good