proxygen
ThreadSafeSSLSessionCacheTest.cpp File Reference
#include <wangle/client/ssl/ThreadSafeSSLSessionCache.h>
#include <wangle/client/ssl/test/TestUtil.h>
#include <folly/Conv.h>
#include <folly/Memory.h>
#include <thread>
#include <gtest/gtest.h>
#include <gmock/gmock.h>

Go to the source code of this file.

Classes

class  FakeSessionCallbacks
 
class  ThreadSafeSSLSessionCacheTest
 

Functions

 TEST_F (ThreadSafeSSLSessionCacheTest, ReadWrite)
 

Function Documentation

TEST_F ( ThreadSafeSSLSessionCacheTest  ,
ReadWrite   
)

Definition at line 72 of file ThreadSafeSSLSessionCacheTest.cpp.

References wangle::createPersistentTestSession(), EXPECT_GE, and i.

72  {
73  const size_t numRounds = 100;
74 
75  size_t writeOps = 0;
76  size_t readOps = 0;
77 
78  std::thread writer([&] () {
79  for (size_t j = 0; j < numRounds; ++j) {
80  for (size_t i = 0; i < sessions_.size(); ++i) {
81  writeOps++;
82  cache_->setSSLSession(
83  folly::to<std::string>("host ", j, i),
84  createPersistentTestSession(sessions_[i]));
85  }
86  }
87  });
88 
89  std::thread reader([&] () {
90  for (size_t j = 0; j < numRounds; ++j) {
91  for (size_t i = 0; i < sessions_.size(); ++i) {
92  readOps++;
93  auto sess = cache_->getSSLSession(
94  folly::to<std::string>("host ", j, i));
95  if (!sess) {
96  // spinlock around the session.
97  i--;
98  }
99  }
100  }
101  });
102 
103  writer.join();
104  reader.join();
105  EXPECT_GE(readOps, writeOps);
106 }
SSLSessionPtr createPersistentTestSession(std::pair< SSL_SESSION *, size_t > session)
Definition: TestUtil.cpp:350
#define EXPECT_GE(val1, val2)
Definition: gtest.h:1932