Short of putting many thousands of rounds through a rifle, you can increase your chances of taking a reliable gun to a class by doing a couple things.
First, get at least 500 rounds through it with a LOT of lube on the carrier and in the receiver. They all have to wear in and the cleaner in CLP will flush the junk out that gets "smoothed" away. You will notice a point when it starts running a lot smoother. Now you can ease off on the lube and find a clean shirt.
Second, and this can be started during the initial break in, use the various mags you plan to take to class. Don't just load 5-10 rounds in them. Brand new, downloading a mag to get the first few rounds to feed is fine, after that, load them to 28 and shoot the first 10, them load back up to 28. Do this a couple times and them empty the mag. No malfs, it goes in the good pile (number them so if one does mess up you can cull it out).
Third, make sure you shoot it until you get it good and hot, then shoot it a little more. The purpose isn't to blow the gas tube or cook off a round, but to make sure that it runs as well hot as it does cool. This is not always the case.
Once you get past all of these successfully, you will have a good shot at getting through a class without incident. Remember to take lube to the class in your pocket. Those little holes in the side of the bolt carrier are there for a reason. a couple quick squirts whenever that class stops for a break or a discussion will pay big dividends.
Oh, and load as many mags as you can prior to the class. Less loading, more listening. Get your money's worth...