'Test that when isolation level is set to READ COMMITTED get_or_create()
for the same row in concurrent requests does not raise an IntegrityError.'

@ddt.data((outer_atomic(), IntegrityError, None, True), (outer_atomic(read_committed=True), type(None), False, True), (commit_on_success(), IntegrityError, None, True), (commit_on_success(read_committed=True), type(None), False, True))
@ddt.unpack
def test_concurrent_requests(self, transaction_decorator, exception_class, created_in_1, created_in_2):

    if (connection.vendor != 'mysql'):
        raise unittest.SkipTest('Only    works    on    MySQL.')
    class RequestThread(threading.Thread, ):
        '    A    thread    which    runs    a    dummy    view.'
        def __init__(self, delay, **kwargs):
            super(RequestThread, self).__init__(**kwargs)
            self.delay = delay
            self.status = {}
        @transaction_decorator
        def run(self):
            'A    dummy    view.'
            try:
                try:
                    User.objects.get(username='student', email='student@edx.org')
                except User.DoesNotExist:
                    pass
                else:
                    raise AssertionError('Did    not    raise    User.DoesNotExist.')
                if (self.delay > 0):
                    time.sleep(self.delay)
                (__, created) = User.objects.get_or_create(username='student', email='student@edx.org')
            except Exception as exception:
                self.status['exception'] = exception
            else:
                self.status['created'] = created
    thread1 = RequestThread(delay=1)
    thread2 = RequestThread(delay=0)
    thread1.start()
    thread2.start()
    thread2.join()
    thread1.join()
    self.assertIsInstance(thread1.status.get('exception'), exception_class)
    self.assertEqual(thread1.status.get('created'), created_in_1)
    self.assertIsNone(thread2.status.get('exception'))
    self.assertEqual(thread2.status.get('created'), created_in_2)
