We consider the problem of testing if a given function f : double-struck F2n → double-struck F2 is close to any degree d polynomial in n variables, also known as the Reed-Muller testing problem. Alon et al.  proposed and analyzed a natural 2d+1-query test for this problem. This test turned out to be intimately related to the Gowers norm. Alon et. al. showed that this test accepts every degree d polynomial with probability 1, while it rejects functions that are Ω(1)-far with probability Ω(1/(d2d)). We give an asymptotically optimal analysis of this test, and show that it rejects functions that are (even only) Ω(2-d)-far with Ω(1)-probability (so the rejection probability is a universal constant independent of d and n). This implies a tight relationship between the (d + 1)st-Gowers norm of a function and its maximal correlation with degree d polynomials, when the correlation is close to 1. Our proof works by induction on n and yields a new analysis of even the classical Blum-Luby-Rubinfeld  linearity test, for the setting of functions mapping double-struck F2n to double-struck F2. The optimality follows from a tighter analysis of counterexamples to the "inverse conjecture for the Gowers norm" constructed by , . Our result has several implications. First, it shows that the Gowers norm test is tolerant, in that it also accepts close codewords. Second, it improves the parameters of an XOR lemma for polynomials given by Viola and Wigderson . Third, it implies a "query hierarchy"result for property testing of affine-invariant properties. That is, for every function q(n), it gives an affine-invariant property that is testable with O(q(n))-queries, but not with o(q(n))-queries, complementing an analogous result of  for graph properties.