|
15 | 15 | // specific language governing permissions and limitations
|
16 | 16 | // under the License.
|
17 | 17 |
|
18 |
| -#include <future> |
19 | 18 | #include <string_view>
|
20 | 19 |
|
21 | 20 | #include "gtest/gtest.h"
|
|
33 | 32 | #include "arrow/testing/gtest_util.h"
|
34 | 33 | #include "arrow/testing/random.h"
|
35 | 34 | #include "arrow/type.h"
|
| 35 | +#include "arrow/util/future.h" |
| 36 | +#include "arrow/util/thread_pool.h" |
36 | 37 | #include "parquet/arrow/reader.h"
|
37 | 38 | #include "parquet/encryption/crypto_factory.h"
|
38 | 39 | #include "parquet/encryption/encryption_internal.h"
|
@@ -166,22 +167,35 @@ class DatasetEncryptionTestBase : public testing::TestWithParam<CompressionParam
|
166 | 167 | // Create the dataset
|
167 | 168 | ASSERT_OK_AND_ASSIGN(auto dataset, dataset_factory->Finish());
|
168 | 169 |
|
169 |
| - std::vector<std::future<Result<std::shared_ptr<Table>>>> threads; |
| 170 | + if (concurrently) { |
| 171 | + // start with a single thread so we are more likely to build up a queue of jobs |
| 172 | + ASSERT_OK_AND_ASSIGN(auto pool, arrow::internal::ThreadPool::Make(1)); |
| 173 | + std::vector<Future<std::shared_ptr<Table>>> threads; |
| 174 | + |
| 175 | + // Read dataset above multiple times concurrently to see that is thread-safe. |
| 176 | + for (size_t i = 0; i < 100; ++i) { |
| 177 | + threads.push_back( |
| 178 | + DeferNotOk(pool->Submit(DatasetEncryptionTestBase::read, dataset))); |
| 179 | + } |
170 | 180 |
|
171 |
| - // Read dataset above multiple times concurrently to see that is thread-safe. |
172 |
| - // Reuse the dataset above to scan it twice to make sure decryption works correctly. |
173 |
| - const size_t attempts = concurrently ? 1000 : 2; |
174 |
| - for (size_t i = 0; i < attempts; ++i) { |
175 |
| - if (concurrently) { |
176 |
| - threads.push_back(std::async(DatasetEncryptionTestBase::read, dataset)); |
177 |
| - } else { |
178 |
| - ASSERT_OK_AND_ASSIGN(auto read_table, read(dataset)); |
| 181 | + // ramp up parallelism |
| 182 | + ASSERT_OK(pool->SetCapacity(16)); |
| 183 | + // ensure there are sufficient jobs to see concurrent processing |
| 184 | + ASSERT_GT(pool->GetNumTasks(), 16); |
| 185 | + printf("%d", pool->GetNumTasks()); |
| 186 | + |
| 187 | + // wait for all jobs to finish |
| 188 | + pool->WaitForIdle(); |
| 189 | + |
| 190 | + // assert correctness of jobs |
| 191 | + for (auto& thread : threads) { |
| 192 | + ASSERT_OK_AND_ASSIGN(auto read_table, thread.result()); |
179 | 193 | AssertTablesEqual(*read_table, *table_);
|
180 | 194 | }
|
181 |
| - } |
182 |
| - if (concurrently) { |
183 |
| - for (auto& thread : threads) { |
184 |
| - ASSERT_OK_AND_ASSIGN(auto read_table, thread.get()); |
| 195 | + } else { |
| 196 | + // Reuse the dataset above to scan it twice to make sure decryption works correctly. |
| 197 | + for (size_t i = 0; i < 2; ++i) { |
| 198 | + ASSERT_OK_AND_ASSIGN(auto read_table, read(dataset)); |
185 | 199 | AssertTablesEqual(*read_table, *table_);
|
186 | 200 | }
|
187 | 201 | }
|
|
0 commit comments