def test_shuffling_queue_with_ngrams(synthetic_dataset):
    """Read data without tensorflow shuffling queue and with it (no rowgroup shuffling). Read ngrams
    Check the the order is deterministic within unshuffled read and is random with shuffled read"""
    fields = {
        0: [TestSchema.id],
        1: [TestSchema.id],
        2: [TestSchema.id]
    }

    # Expecting delta between ids to be 1. Setting 1.5 as upper bound
    ngram = NGram(fields=fields, delta_threshold=1.5, timestamp_field=TestSchema.id)
    unshuffled_1, _ = _read_from_tf_tensors(synthetic_dataset, 30, shuffling_queue_capacity=0, min_after_dequeue=0,
                                            ngram=ngram)
    unshuffled_2, _ = _read_from_tf_tensors(synthetic_dataset, 30, shuffling_queue_capacity=0, min_after_dequeue=0,
                                            ngram=ngram)

    shuffled_1, shuffled_1_ngram = \
        _read_from_tf_tensors(synthetic_dataset, 20, shuffling_queue_capacity=30, min_after_dequeue=29, ngram=ngram)
    shuffled_2, _ = \
        _read_from_tf_tensors(synthetic_dataset, 20, shuffling_queue_capacity=30, min_after_dequeue=29, ngram=ngram)

    # shuffled_1_ngram is a dictionary of named tuple indexed by time:
    # {0: (tensor, tensor, tensor, ...),
    #  1: (tensor, tensor, tensor, ...),
    #  ...}
    for row_tensor in shuffled_1_ngram.values():
        _assert_all_tensors_have_shape(row_tensor)

    # shuffled_1 is a list of dictionaries of named tuples indexed by time:
    # [{0: (tensor, tensor, tensor, ...),
    #  1: (tensor, tensor, tensor, ...),
    #  ...}
    # {0: (tensor, tensor, tensor, ...),
    #  1: (tensor, tensor, tensor, ...),
    #  ...},...
    # ]
    for one_ngram_dict in shuffled_1:
        _assert_expected_rows_data(synthetic_dataset.data, one_ngram_dict.values())

    def flatten(list_of_ngrams):
        return [row for seq in list_of_ngrams for row in seq.values()]

    assert [f.id for f in flatten(unshuffled_1)] == [f.id for f in flatten(unshuffled_2)]

    assert [f.id for f in flatten(unshuffled_1)] != [f.id for f in flatten(shuffled_2)]
    assert [f.id for f in flatten(shuffled_1)] != [f.id for f in flatten(shuffled_2)]
Read data without tensorflow shuffling queue and with it (no rowgroup shuffling). Read ngrams
    Check the the order is deterministic within unshuffled read and is random with shuffled read
petastorm/tests/test_tf_utils.py