I think the salient point in your question can be more explicitly stated as:
What determines which advantages are fair and which are unfair to have during an exam?
Going to the extreme for fair advantages: Is not being sick on the exam day cheating? Is not being hungry cheating? Is not staying up the night before cheating? Is attending every lecture and study session fair? Is studying for the exam fair? Is being more intelligent than your classmates fair? Is always marking the correct answer fair? Is lucking out and having exam question be on something you happen to be very experienced with (database question for a seasoned database programmer) fair?
All of these are obviously fine. Yet consider the other extreme:
Is smoking during the exam fair? Is taking Adderall fair? Is doing cocaine before the exam fair? Is hacking the instructor's computer to get answers fair? Is manipulating the TA to trick them into revealing answers to you fair? Is bringing a cheatsheet or phone with you fair? Is making someone else take the test with you fair?
These aren't qualitatively different from the previous group. Sure, some are distinguished by being illegal (hacking) but many are accepted ways of improving performance in all but exam contexts (having reference materials at hand, looking up things you don't know online, collaborating with peers).
I posit to resolve this as follows: Exams are not a meritocracy. The point isn't to enforce some sort of egalitarian principle or to "let the best man win". The exam is part of the course, and the aim of the course is to make students proficient with the course material. The exam exists as a target for the students to aim for as they are independently studying and preparing.
If you agree to this point, then the question of what is fair becomes trivial: The instructor allows as "fair" any behavior that they deem conducive to learning.
For example, studying for days on end may be unfair to students who don't have as much time to study, but encouraging students to study benefits learning, so instructors deem it fair and sanction it.
On the other hand, stealing exam questions beforehand is an extremely effective way to do "well" on the exam, but not only do you learn nothing this way, if you get caught and punished there may be severe consequences for your future career. Theft of questions is a mechanism by which the exam is enabled to act as a perverse incentive. The instructor, therefore, tries to remedy this by specifically banning this mechanism. That such banned mechanism are called "unfair" (as if to imply some egalitarian or justicial purpose) is, I think, an artifact of language.
Coming back to your question:
Is it fair for me to drink caffeine during tests?
Let's accept the premise that drinking coffee increases your performance (I am skeptical of this).
Is this conducive to the learning process? There is a tiny positive effect - your brain performing better during the exam means you will be more likely to experience those moments of really grasping a concept when you are forced to use it during the exam.
Does it facilitate a perverse incentive? Dubious.
- If the caffeine helps mental performance that much, students will probably start drinking it during courses or when they study, which means their learning will be enhanced.
- If they drink only during the exam, their score will be slightly inflated compared to other students. But the effect is tiny and self-damping: The more effective coffee proves to be, the more students will start drinking it, and everyone will end up on equal footing anyway.
- The smell of coffee may slightly disadvantage other students, which has a very small positive effect on your grade if the exam is graded on a curve. However, the effect is tiny, and if any student feels otherwise, they can always complain and ask you to remove the offending beverage.
Taken together, it seems like there's a few positive and a few negative effects, but all are very small. The only thing being meaningfully incentivized is the business of the coffee shop - but this does not detract from the learning process.
On the other hand, some people enjoy drinking coffee, it makes them feel more comfortable in the exam, and if it lets them believe they have control over their performance and have "stacked the deck" in their own favor, the psychological motivation may contribute to a more positive attitude towards the course in general. Altogether, when you are trying to teach someone something, it probably works better if they are physically comfortable rather than not. So I don't think it should be considered unfair or banned, unless students are very clumsy and constantly spill the coffee, litter by leaving empty cups around, or otherwise go about it in an unacceptable manner.
As an addendum, with more "hardcore" performance enhancing drugs, this may not be the case. For example, instructors would most likely be against taking drugs like Adderall (although this is very difficult to enforce) because it would incentivize the abuse of these drugs. Adderall abuse has serious harmful consequences, unlike caffeine abuse which is not commonly thought to be harmful.