Minor bug correction to grant define.

The previous construction caused a race condition where two different grants could get assigned the same file name.

Add tests for these cases.