Glucose test. What is it?

Sarah • Wife. Momma to a 2 year old. Praying for our rainbow baby.
This is my first pregnancy and I'm 16 weeks along. My doctor hasn't even mention this test to me yet, however I hear about it a lot from pregnant woman further along. I know the point of the test but here is what I don't know...first off, what exactly goes down at this test? I hear the first test take a whole hour, and if you fail that, the next test is 3 hours long. Why so long for both?! Do you have to drink that syrup stuff for both? Also, is this test optional?