Skip to content

Commit

Permalink
Fix ASAN error and enable ASAN in CI
Browse files Browse the repository at this point in the history
Enables ASAN tests in CI and fixes the circular reference it found.
  • Loading branch information
allada committed Jul 16, 2023
1 parent a428e23 commit e0cc0f9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
35 changes: 33 additions & 2 deletions .github/workflows/main.yml
@@ -1,6 +1,6 @@
name: CI

# Controls when the workflow will run
# Controls when the workflow will run.
on:
push:
branches: [ master ]
Expand All @@ -9,7 +9,7 @@ on:

jobs:
unit-test:
# The type of runner that the job will run on
# The type of runner that the job will run on.
runs-on: ubuntu-22.04
strategy:
matrix:
Expand Down Expand Up @@ -66,3 +66,34 @@ jobs:

- name: Run tests
run: ./run_integration_tests.sh

asan-tests:
# The type of runner that the job will run on.
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3.5.3
with:
fetch-depth: 0

- uses: docker/setup-buildx-action@v2
- uses: docker/build-push-action@v4
with:
context: .
file: ./deployment-examples/docker-compose/Dockerfile
build-args: |
ADDITIONAL_BAZEL_FLAGS=--config=asan
target: builder-externals-built
load: true # This brings the build into `docker images` from buildx.
tags: allada/turbo-cache:asan-test
cache-from: type=gha,scope=main
cache-to: type=gha,scope=main,mode=max

- name: Bazel test
run: |
docker run \
--rm \
-e CC=clang \
-v $PWD:/root/turbo-cache allada/turbo-cache:asan-test \
bazel test \
--config=asan \
//...
2 changes: 1 addition & 1 deletion cas/store/default_store_factory.rs
Expand Up @@ -56,7 +56,7 @@ pub fn store_factory<'a>(backend: &'a StoreConfig, store_manager: &'a Arc<StoreM
store_factory(&config.slow, store_manager).await?,
)),
StoreConfig::filesystem(config) => Arc::new(<FilesystemStore>::new(config).await?),
StoreConfig::ref_store(config) => Arc::new(RefStore::new(config, store_manager.clone())),
StoreConfig::ref_store(config) => Arc::new(RefStore::new(config, Arc::downgrade(store_manager))),
StoreConfig::size_partitioning(config) => Arc::new(SizePartitioningStore::new(
config,
store_factory(&config.lower_store, store_manager).await?,
Expand Down
11 changes: 6 additions & 5 deletions cas/store/ref_store.rs
Expand Up @@ -14,10 +14,10 @@

use std::cell::UnsafeCell;
use std::pin::Pin;
use std::sync::Arc;
use std::sync::Mutex;
use std::sync::{Arc, Mutex, Weak};

use async_trait::async_trait;
use error::ResultExt;

use buf_channel::{DropCloserReadHalf, DropCloserWriteHalf};
use common::DigestInfo;
Expand All @@ -37,12 +37,12 @@ unsafe impl Sync for StoreReference {}

pub struct RefStore {
ref_store_name: String,
store_manager: Arc<StoreManager>,
store_manager: Weak<StoreManager>,
ref_store: StoreReference,
}

impl RefStore {
pub fn new(config: &config::stores::RefStore, store_manager: Arc<StoreManager>) -> Self {
pub fn new(config: &config::stores::RefStore, store_manager: Weak<StoreManager>) -> Self {
RefStore {
ref_store_name: config.name.clone(),
store_manager,
Expand Down Expand Up @@ -75,7 +75,8 @@ impl RefStore {
.mux
.lock()
.map_err(|e| make_err!(Code::Internal, "Failed to lock mutex in ref_store : {:?}", e))?;
if let Some(store) = self.store_manager.get_store(&self.ref_store_name) {
let store_manager = self.store_manager.upgrade().err_tip(|| "Store manager is gone")?;
if let Some(store) = store_manager.get_store(&self.ref_store_name) {
unsafe {
*ref_store = Some(store.clone());
return Ok((*ref_store).as_ref().unwrap());
Expand Down
12 changes: 6 additions & 6 deletions cas/store/tests/ref_store_test.rs
Expand Up @@ -29,7 +29,7 @@ mod ref_store_tests {

const VALID_HASH1: &str = "0123456789abcdef000000000000000000010000000000000123456789abcdef";

fn setup_stores() -> (Arc<MemoryStore>, Arc<RefStore>) {
fn setup_stores() -> (Arc<StoreManager>, Arc<MemoryStore>, Arc<RefStore>) {
let store_manager = Arc::new(StoreManager::new());

let memory_store_owned = Arc::new(MemoryStore::new(&config::stores::MemoryStore::default()));
Expand All @@ -39,15 +39,15 @@ mod ref_store_tests {
&config::stores::RefStore {
name: "foo".to_string(),
},
store_manager.clone(),
Arc::downgrade(&store_manager),
));
store_manager.add_store("bar", ref_store_owned.clone());
(memory_store_owned, ref_store_owned)
(store_manager, memory_store_owned, ref_store_owned)
}

#[tokio::test]
async fn has_test() -> Result<(), Error> {
let (memory_store_owned, ref_store_owned) = setup_stores();
let (_store_manager, memory_store_owned, ref_store_owned) = setup_stores();

const VALUE1: &str = "13";
{
Expand All @@ -73,7 +73,7 @@ mod ref_store_tests {

#[tokio::test]
async fn get_test() -> Result<(), Error> {
let (memory_store_owned, ref_store_owned) = setup_stores();
let (_store_manager, memory_store_owned, ref_store_owned) = setup_stores();

const VALUE1: &str = "13";
{
Expand All @@ -100,7 +100,7 @@ mod ref_store_tests {

#[tokio::test]
async fn update_test() -> Result<(), Error> {
let (memory_store_owned, ref_store_owned) = setup_stores();
let (_store_manager, memory_store_owned, ref_store_owned) = setup_stores();

const VALUE1: &str = "13";
{
Expand Down
8 changes: 6 additions & 2 deletions deployment-examples/docker-compose/Dockerfile
Expand Up @@ -18,6 +18,8 @@ ARG OS_VERSION=22.04
ARG OPT_LEVEL=opt
# Compiler to use.
ARG CC=clang
# Additional bazel flags.
ARG ADDITIONAL_BAZEL_FLAGS=


# Builder that contains the OS dependencies.
Expand Down Expand Up @@ -90,17 +92,19 @@ FROM builder-with-externals as builder-externals-built
WORKDIR /root/turbo-cache
ARG OPT_LEVEL
ARG CC
ARG ADDITIONAL_BAZEL_FLAGS
COPY proto/ proto/
COPY --from=builder-external-deps /root/external-targets.txt /root/external-targets.txt
RUN bazel build -c ${OPT_LEVEL} --target_pattern_file=/root/external-targets.txt
RUN bazel build -c ${OPT_LEVEL} ${ADDITIONAL_BAZEL_FLAGS} --target_pattern_file=/root/external-targets.txt


# Builder to do the remaining build. At this point most of our externals should be built.
FROM builder-externals-built as builder
ARG OPT_LEVEL
ARG CC
ARG ADDITIONAL_BAZEL_FLAGS
COPY . .
RUN bazel build -c ${OPT_LEVEL} //cas && \
RUN bazel build -c ${OPT_LEVEL} ${ADDITIONAL_BAZEL_FLAGS} //cas && \
cp ./bazel-bin/cas/cas /root/turbo-cache-bin


Expand Down

0 comments on commit e0cc0f9

Please sign in to comment.