So what's happening is that Gazebo is putting your insert instructions in a queue this->dataPtr->factoryMsgs which gets processed in a future iteration, based on this->dataPtr->processMsgsPeriod.
It looks like you'll need to step a few iterations while checking that the model has been inserted, you could check World::Models() to see if the model has been inserted.