Added test and fix for race condition in contract resolving

We encountered an issue when initializing multiple serializers at the same time using shared contract resolver cache. 

The test written does not actually use shared cache, but imitates it to ensure that the test fails more often. If not written this way (but with sharedCache = true) the race condition would still appear but only not as often.