Hi.
School can be very stressful. The pressure to do well, meet the expectations that others have for you and you have for yourself and plan out your entire future can seem very overwhelming.
While doing well in school is important, you need to strike some sort of balance for yourself. Your failure of one test, while not a good thing, seems to be taking more of a toll on you than it should. Did you fail the test because you didn't prepare? Or was it just a difficult test? If it was a difficult test, you might try speaking with the teacher to make sure you understand how to avoid this problem in the future.
It seems to me that you might be putting extra pressure on yourself scholastically to protect yourself from the risks involved in making friends or doing other activities. It's important to remember that not all the learning you do in high school happens in a classroom. Making friends is a good way to figure out who you are, what you like and how you want yourself to be.
Friends can also have a positive effect on your grades. When you extend yourself to others, you'll often find that they extend themselves to you. Acquaintances can become friends who'll offer you the support you need when something in your life goes wrong--such as a failed test.
There are many things you can do to be more social--joining clubs at school, trying some extracurricular activities or phoning up one of your project friends just to hang out are a few options. You can also check out some other Help Me Heathers for advice on making and keeping friends.
My suggestion is that you keep studying--it's important and you obviously value your education--but also try to find some time to let other people into your life. This is one instance where you can have the best of both worlds if you're careful with your time and willing to test yourself in new ways. Of course, balance can be very difficult to achieve, so don't give up if it doesn't happen right away.