gRPC: run tests with and without gRPC (#47770)

The migration to gRPC will take a significant amount of time, and until
we are fully migrated and are able to remove the non-gRPC codepaths, we
need to be confident that both codepaths work correctly.

Our options here include: 
1) duplicating every test to run with and without gRPC
2) adding a `TestMain` to every test package that reruns the suite with
and without gRPC
3) manually adding tests for all the codepaths that are interesting to
gRPC
4) always running both the HTTP and gRPC codepaths in parallel
5) mirror the test steps in CI to run both with and without gRPC

None of the options are good, but a solution here is necessary avoid
introducing regressions during the migration. This PR implements option
5 because it is the least bad option that is also the easiest to rip out
when it is no longer needed.

This PR updates our CI pipeline generator to duplicate most of our go
tests (everything except database tests) as well as our backend
integration tests. It does this by adding the environment variable
`SG_FEATURE_FLAG_GRPC`, which is respected when clients are deciding
whether to use gRPC or HTTP.

Co-authored-by: Geoffrey Gilmore <me@ggilmore.net>
This commit is contained in:
Camden Cheek 2023-02-17 12:38:41 -07:00 committed by GitHub
parent 5b9e5e229f
commit fe50452af7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 243 additions and 62 deletions

View File

@ -3,10 +3,11 @@ package api
import (
"context"
"net/http/httptest"
"reflect"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sourcegraph/go-ctags"
"github.com/sourcegraph/sourcegraph/cmd/symbols/fetcher"
"github.com/sourcegraph/sourcegraph/cmd/symbols/gitserver"
@ -135,8 +136,8 @@ func TestHandler(t *testing.T) {
if testCase.expected != nil {
t.Errorf("unexpected search result. want=%+v, have=nil", testCase.expected)
}
} else if !reflect.DeepEqual(resultSymbols, testCase.expected) {
t.Errorf("unexpected search result. want=%+v, have=%+v", testCase.expected, resultSymbols)
} else if diff := cmp.Diff(resultSymbols, testCase.expected, cmpopts.EquateEmpty()); diff != "" {
t.Errorf("unexpected search result. diff: %s", diff)
}
})
}

View File

@ -6,6 +6,7 @@ PORT=${PORT:-"7080"}
URL="http://localhost:$PORT"
DATA=${DATA:-"/tmp/sourcegraph-data"}
SOURCEGRAPH_LICENSE_GENERATION_KEY=${SOURCEGRAPH_LICENSE_GENERATION_KEY:-""}
SG_FEATURE_FLAG_GRPC=${SG_FEATURE_FLAG_GRPC:-"false"}
echo "--- Checking for existing Sourcegraph instance at $URL"
if curl --output /dev/null --silent --head --fail "$URL"; then
@ -40,6 +41,7 @@ docker run "$@" \
-e DEBUG=t \
-e ALLOW_SINGLE_DOCKER_CODE_INSIGHTS=t \
-e SOURCEGRAPH_LICENSE_GENERATION_KEY="$SOURCEGRAPH_LICENSE_GENERATION_KEY" \
-e SG_FEATURE_FLAG_GRPC="$SG_FEATURE_FLAG_GRPC" \
--volume "$DATA/config:/etc/sourcegraph" \
--volume "$DATA/data:/var/opt/sourcegraph" \
"$IMAGE"

View File

@ -17,7 +17,7 @@ The default run type.
- Pipeline for `Go` changes:
- **Metadata**: Pipeline metadata
- **Linters and static analysis**: Run sg lint
- **Go checks**: Test (all), Test (enterprise/internal/insights), Test (internal/database), Test (internal/repos), Test (enterprise/internal/batches), Test (cmd/frontend), Test (enterprise/internal/database), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (dev/sg), Build
- **Go checks**: Test (all), Test (all (gRPC)), Test (enterprise/internal/insights), Test (enterprise/internal/insights (gRPC)), Test (internal/repos), Test (internal/repos (gRPC)), Test (enterprise/internal/batches), Test (enterprise/internal/batches (gRPC)), Test (cmd/frontend), Test (cmd/frontend (gRPC)), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Test (dev/sg), Test (dev/sg (gRPC)), Test (internal/database), Test (enterprise/internal/database), Build
- Upload build trace
- Pipeline for `Client` changes:
@ -32,12 +32,12 @@ The default run type.
- **Metadata**: Pipeline metadata
- **Linters and static analysis**: GraphQL lint
- **Client checks**: Puppeteer tests prep, Puppeteer tests for chrome extension, Puppeteer tests chunk #1, Puppeteer tests chunk #2, Puppeteer tests chunk #3, Puppeteer tests chunk #4, Puppeteer tests chunk #5, Puppeteer tests chunk #6, Puppeteer tests chunk #7, Puppeteer tests chunk #8, Puppeteer tests chunk #9, Puppeteer tests chunk #10, Puppeteer tests chunk #11, Puppeteer tests chunk #12, Puppeteer tests chunk #13, Puppeteer tests chunk #14, Upload Storybook to Chromatic, Test (all), Build, Enterprise build, Test (client/web), Test (client/browser), Test (client/jetbrains), Build TS, ESLint (all), Stylelint (all)
- **Go checks**: Test (all), Test (enterprise/internal/insights), Test (internal/database), Test (internal/repos), Test (enterprise/internal/batches), Test (cmd/frontend), Test (enterprise/internal/database), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (dev/sg), Build
- **Go checks**: Test (all), Test (all (gRPC)), Test (enterprise/internal/insights), Test (enterprise/internal/insights (gRPC)), Test (internal/repos), Test (internal/repos (gRPC)), Test (enterprise/internal/batches), Test (enterprise/internal/batches (gRPC)), Test (cmd/frontend), Test (cmd/frontend (gRPC)), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Test (dev/sg), Test (dev/sg (gRPC)), Test (internal/database), Test (enterprise/internal/database), Build
- Upload build trace
- Pipeline for `DatabaseSchema` changes:
- **Metadata**: Pipeline metadata
- **DB backcompat tests**: Backcompat test (all), Backcompat test (enterprise/internal/insights), Backcompat test (internal/database), Backcompat test (internal/repos), Backcompat test (enterprise/internal/batches), Backcompat test (cmd/frontend), Backcompat test (enterprise/internal/database), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (dev/sg)
- **DB backcompat tests**: Backcompat test (all), Backcompat test (all (gRPC)), Backcompat test (enterprise/internal/insights), Backcompat test (enterprise/internal/insights (gRPC)), Backcompat test (internal/repos), Backcompat test (internal/repos (gRPC)), Backcompat test (enterprise/internal/batches), Backcompat test (enterprise/internal/batches (gRPC)), Backcompat test (cmd/frontend), Backcompat test (cmd/frontend (gRPC)), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Backcompat test (dev/sg), Backcompat test (dev/sg (gRPC)), Backcompat test (internal/database), Backcompat test (enterprise/internal/database)
- Upload build trace
- Pipeline for `Docs` changes:
@ -182,10 +182,10 @@ Base pipeline (more steps might be included based on branch changes):
- **Image security scans**: Scan alpine-3.14, Scan cadvisor, Scan codeinsights-db, Scan codeintel-db, Scan frontend, Scan github-proxy, Scan gitserver, Scan grafana, Scan indexed-searcher, Scan jaeger-agent, Scan jaeger-all-in-one, Scan blobstore2, Scan node-exporter, Scan postgres-12-alpine, Scan postgres_exporter, Scan precise-code-intel-worker, Scan prometheus, Scan prometheus-gcp, Scan redis-cache, Scan redis-store, Scan redis_exporter, Scan repo-updater, Scan search-indexer, Scan searcher, Scan symbols, Scan syntax-highlighter, Scan worker, Scan migrator, Scan executor, Scan executor-vm, Scan batcheshelper, Scan opentelemetry-collector, Scan sg
- **Linters and static analysis**: GraphQL lint, Run sg lint
- **Client checks**: Puppeteer tests prep, Puppeteer tests for chrome extension, Puppeteer tests chunk #1, Puppeteer tests chunk #2, Puppeteer tests chunk #3, Puppeteer tests chunk #4, Puppeteer tests chunk #5, Puppeteer tests chunk #6, Puppeteer tests chunk #7, Puppeteer tests chunk #8, Puppeteer tests chunk #9, Puppeteer tests chunk #10, Puppeteer tests chunk #11, Puppeteer tests chunk #12, Puppeteer tests chunk #13, Puppeteer tests chunk #14, Upload Storybook to Chromatic, Test (all), Build, Enterprise build, Test (client/web), Test (client/browser), Test (client/jetbrains), Build TS, ESLint (all), Stylelint (all)
- **Go checks**: Test (all), Test (enterprise/internal/insights), Test (internal/database), Test (internal/repos), Test (enterprise/internal/batches), Test (cmd/frontend), Test (enterprise/internal/database), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (dev/sg), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (enterprise/internal/insights), Backcompat test (internal/database), Backcompat test (internal/repos), Backcompat test (enterprise/internal/batches), Backcompat test (cmd/frontend), Backcompat test (enterprise/internal/database), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (dev/sg)
- **Go checks**: Test (all), Test (all (gRPC)), Test (enterprise/internal/insights), Test (enterprise/internal/insights (gRPC)), Test (internal/repos), Test (internal/repos (gRPC)), Test (enterprise/internal/batches), Test (enterprise/internal/batches (gRPC)), Test (cmd/frontend), Test (cmd/frontend (gRPC)), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Test (dev/sg), Test (dev/sg (gRPC)), Test (internal/database), Test (enterprise/internal/database), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (all (gRPC)), Backcompat test (enterprise/internal/insights), Backcompat test (enterprise/internal/insights (gRPC)), Backcompat test (internal/repos), Backcompat test (internal/repos (gRPC)), Backcompat test (enterprise/internal/batches), Backcompat test (enterprise/internal/batches (gRPC)), Backcompat test (cmd/frontend), Backcompat test (cmd/frontend (gRPC)), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Backcompat test (dev/sg), Backcompat test (dev/sg (gRPC)), Backcompat test (internal/database), Backcompat test (enterprise/internal/database)
- **CI script tests**: test-trace-command.sh
- **Integration tests**: Backend integration tests, Code Intel QA
- **Integration tests**: Backend integration tests (gRPC), Backend integration tests, Code Intel QA
- **End-to-end tests**: Executors E2E, Sourcegraph E2E, Sourcegraph QA, Sourcegraph Cluster (deploy-sourcegraph) QA, Sourcegraph Upgrade
- **Publish images**: alpine-3.14, cadvisor, codeinsights-db, codeintel-db, frontend, github-proxy, gitserver, grafana, indexed-searcher, jaeger-agent, jaeger-all-in-one, blobstore, blobstore2, node-exporter, postgres-12-alpine, postgres_exporter, precise-code-intel-worker, prometheus, prometheus-gcp, redis-cache, redis-store, redis_exporter, repo-updater, search-indexer, searcher, symbols, syntax-highlighter, worker, migrator, executor, executor-vm, batcheshelper, opentelemetry-collector, server, sg, Publish executor image, Publish executor binary, Publish docker registry mirror image
- Upload build trace
@ -202,10 +202,10 @@ Base pipeline (more steps might be included based on branch changes):
- **Image security scans**: Scan alpine-3.14, Scan cadvisor, Scan codeinsights-db, Scan codeintel-db, Scan frontend, Scan github-proxy, Scan gitserver, Scan grafana, Scan indexed-searcher, Scan jaeger-agent, Scan jaeger-all-in-one, Scan blobstore2, Scan node-exporter, Scan postgres-12-alpine, Scan postgres_exporter, Scan precise-code-intel-worker, Scan prometheus, Scan prometheus-gcp, Scan redis-cache, Scan redis-store, Scan redis_exporter, Scan repo-updater, Scan search-indexer, Scan searcher, Scan symbols, Scan syntax-highlighter, Scan worker, Scan migrator, Scan executor, Scan executor-vm, Scan batcheshelper, Scan opentelemetry-collector, Scan sg
- **Linters and static analysis**: GraphQL lint, Run sg lint
- **Client checks**: Puppeteer tests prep, Puppeteer tests for chrome extension, Puppeteer tests chunk #1, Puppeteer tests chunk #2, Puppeteer tests chunk #3, Puppeteer tests chunk #4, Puppeteer tests chunk #5, Puppeteer tests chunk #6, Puppeteer tests chunk #7, Puppeteer tests chunk #8, Puppeteer tests chunk #9, Puppeteer tests chunk #10, Puppeteer tests chunk #11, Puppeteer tests chunk #12, Puppeteer tests chunk #13, Puppeteer tests chunk #14, Upload Storybook to Chromatic, Test (all), Build, Enterprise build, Test (client/web), Test (client/browser), Test (client/jetbrains), Build TS, ESLint (all), Stylelint (all)
- **Go checks**: Test (all), Test (enterprise/internal/insights), Test (internal/database), Test (internal/repos), Test (enterprise/internal/batches), Test (cmd/frontend), Test (enterprise/internal/database), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (dev/sg), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (enterprise/internal/insights), Backcompat test (internal/database), Backcompat test (internal/repos), Backcompat test (enterprise/internal/batches), Backcompat test (cmd/frontend), Backcompat test (enterprise/internal/database), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (dev/sg)
- **Go checks**: Test (all), Test (all (gRPC)), Test (enterprise/internal/insights), Test (enterprise/internal/insights (gRPC)), Test (internal/repos), Test (internal/repos (gRPC)), Test (enterprise/internal/batches), Test (enterprise/internal/batches (gRPC)), Test (cmd/frontend), Test (cmd/frontend (gRPC)), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Test (dev/sg), Test (dev/sg (gRPC)), Test (internal/database), Test (enterprise/internal/database), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (all (gRPC)), Backcompat test (enterprise/internal/insights), Backcompat test (enterprise/internal/insights (gRPC)), Backcompat test (internal/repos), Backcompat test (internal/repos (gRPC)), Backcompat test (enterprise/internal/batches), Backcompat test (enterprise/internal/batches (gRPC)), Backcompat test (cmd/frontend), Backcompat test (cmd/frontend (gRPC)), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Backcompat test (dev/sg), Backcompat test (dev/sg (gRPC)), Backcompat test (internal/database), Backcompat test (enterprise/internal/database)
- **CI script tests**: test-trace-command.sh
- **Integration tests**: Backend integration tests, Code Intel QA
- **Integration tests**: Backend integration tests (gRPC), Backend integration tests, Code Intel QA
- **End-to-end tests**: Executors E2E, Sourcegraph E2E, Sourcegraph QA, Sourcegraph Cluster (deploy-sourcegraph) QA, Sourcegraph Upgrade
- **Publish images**: alpine-3.14, cadvisor, codeinsights-db, codeintel-db, frontend, github-proxy, gitserver, grafana, indexed-searcher, jaeger-agent, jaeger-all-in-one, blobstore, blobstore2, node-exporter, postgres-12-alpine, postgres_exporter, precise-code-intel-worker, prometheus, prometheus-gcp, redis-cache, redis-store, redis_exporter, repo-updater, search-indexer, searcher, symbols, syntax-highlighter, worker, migrator, executor, executor-vm, batcheshelper, opentelemetry-collector, server, sg
- Upload build trace
@ -251,10 +251,10 @@ Base pipeline (more steps might be included based on branch changes):
- **Image security scans**: Scan alpine-3.14, Scan cadvisor, Scan codeinsights-db, Scan codeintel-db, Scan frontend, Scan github-proxy, Scan gitserver, Scan grafana, Scan indexed-searcher, Scan jaeger-agent, Scan jaeger-all-in-one, Scan blobstore2, Scan node-exporter, Scan postgres-12-alpine, Scan postgres_exporter, Scan precise-code-intel-worker, Scan prometheus, Scan prometheus-gcp, Scan redis-cache, Scan redis-store, Scan redis_exporter, Scan repo-updater, Scan search-indexer, Scan searcher, Scan symbols, Scan syntax-highlighter, Scan worker, Scan migrator, Scan executor, Scan executor-vm, Scan batcheshelper, Scan opentelemetry-collector, Scan sg
- **Linters and static analysis**: GraphQL lint, Run sg lint
- **Client checks**: Puppeteer tests prep, Puppeteer tests for chrome extension, Puppeteer tests chunk #1, Puppeteer tests chunk #2, Puppeteer tests chunk #3, Puppeteer tests chunk #4, Puppeteer tests chunk #5, Puppeteer tests chunk #6, Puppeteer tests chunk #7, Puppeteer tests chunk #8, Puppeteer tests chunk #9, Puppeteer tests chunk #10, Puppeteer tests chunk #11, Puppeteer tests chunk #12, Puppeteer tests chunk #13, Puppeteer tests chunk #14, Upload Storybook to Chromatic, Test (all), Build, Enterprise build, Test (client/web), Test (client/browser), Test (client/jetbrains), Build TS, ESLint (all), Stylelint (all)
- **Go checks**: Test (all), Test (enterprise/internal/insights), Test (internal/database), Test (internal/repos), Test (enterprise/internal/batches), Test (cmd/frontend), Test (enterprise/internal/database), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (dev/sg), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (enterprise/internal/insights), Backcompat test (internal/database), Backcompat test (internal/repos), Backcompat test (enterprise/internal/batches), Backcompat test (cmd/frontend), Backcompat test (enterprise/internal/database), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (dev/sg)
- **Go checks**: Test (all), Test (all (gRPC)), Test (enterprise/internal/insights), Test (enterprise/internal/insights (gRPC)), Test (internal/repos), Test (internal/repos (gRPC)), Test (enterprise/internal/batches), Test (enterprise/internal/batches (gRPC)), Test (cmd/frontend), Test (cmd/frontend (gRPC)), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Test (dev/sg), Test (dev/sg (gRPC)), Test (internal/database), Test (enterprise/internal/database), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (all (gRPC)), Backcompat test (enterprise/internal/insights), Backcompat test (enterprise/internal/insights (gRPC)), Backcompat test (internal/repos), Backcompat test (internal/repos (gRPC)), Backcompat test (enterprise/internal/batches), Backcompat test (enterprise/internal/batches (gRPC)), Backcompat test (cmd/frontend), Backcompat test (cmd/frontend (gRPC)), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Backcompat test (dev/sg), Backcompat test (dev/sg (gRPC)), Backcompat test (internal/database), Backcompat test (enterprise/internal/database)
- **CI script tests**: test-trace-command.sh
- **Integration tests**: Backend integration tests, Code Intel QA
- **Integration tests**: Backend integration tests (gRPC), Backend integration tests, Code Intel QA
- **End-to-end tests**: Executors E2E, Sourcegraph E2E, Sourcegraph QA, Sourcegraph Cluster (deploy-sourcegraph) QA, Sourcegraph Upgrade
- **Publish images**: alpine-3.14, cadvisor, codeinsights-db, codeintel-db, frontend, github-proxy, gitserver, grafana, indexed-searcher, jaeger-agent, jaeger-all-in-one, blobstore, blobstore2, node-exporter, postgres-12-alpine, postgres_exporter, precise-code-intel-worker, prometheus, prometheus-gcp, redis-cache, redis-store, redis_exporter, repo-updater, search-indexer, searcher, symbols, syntax-highlighter, worker, migrator, executor, executor-vm, batcheshelper, opentelemetry-collector, server, sg, Publish executor image, Publish executor binary
- Upload build trace
@ -276,10 +276,10 @@ Base pipeline (more steps might be included based on branch changes):
- **Image security scans**: Scan alpine-3.14, Scan cadvisor, Scan codeinsights-db, Scan codeintel-db, Scan frontend, Scan github-proxy, Scan gitserver, Scan grafana, Scan indexed-searcher, Scan jaeger-agent, Scan jaeger-all-in-one, Scan blobstore2, Scan node-exporter, Scan postgres-12-alpine, Scan postgres_exporter, Scan precise-code-intel-worker, Scan prometheus, Scan prometheus-gcp, Scan redis-cache, Scan redis-store, Scan redis_exporter, Scan repo-updater, Scan search-indexer, Scan searcher, Scan symbols, Scan syntax-highlighter, Scan worker, Scan migrator, Scan executor, Scan executor-vm, Scan batcheshelper, Scan opentelemetry-collector, Scan sg
- **Linters and static analysis**: GraphQL lint, Run sg lint
- **Client checks**: Puppeteer tests prep, Puppeteer tests for chrome extension, Puppeteer tests chunk #1, Puppeteer tests chunk #2, Puppeteer tests chunk #3, Puppeteer tests chunk #4, Puppeteer tests chunk #5, Puppeteer tests chunk #6, Puppeteer tests chunk #7, Puppeteer tests chunk #8, Puppeteer tests chunk #9, Puppeteer tests chunk #10, Puppeteer tests chunk #11, Puppeteer tests chunk #12, Puppeteer tests chunk #13, Puppeteer tests chunk #14, Upload Storybook to Chromatic, Test (all), Build, Enterprise build, Test (client/web), Test (client/browser), Test (client/jetbrains), Build TS, ESLint (all), Stylelint (all)
- **Go checks**: Test (all), Test (enterprise/internal/insights), Test (internal/database), Test (internal/repos), Test (enterprise/internal/batches), Test (cmd/frontend), Test (enterprise/internal/database), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (dev/sg), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (enterprise/internal/insights), Backcompat test (internal/database), Backcompat test (internal/repos), Backcompat test (enterprise/internal/batches), Backcompat test (cmd/frontend), Backcompat test (enterprise/internal/database), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (dev/sg)
- **Go checks**: Test (all), Test (all (gRPC)), Test (enterprise/internal/insights), Test (enterprise/internal/insights (gRPC)), Test (internal/repos), Test (internal/repos (gRPC)), Test (enterprise/internal/batches), Test (enterprise/internal/batches (gRPC)), Test (cmd/frontend), Test (cmd/frontend (gRPC)), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Test (dev/sg), Test (dev/sg (gRPC)), Test (internal/database), Test (enterprise/internal/database), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (all (gRPC)), Backcompat test (enterprise/internal/insights), Backcompat test (enterprise/internal/insights (gRPC)), Backcompat test (internal/repos), Backcompat test (internal/repos (gRPC)), Backcompat test (enterprise/internal/batches), Backcompat test (enterprise/internal/batches (gRPC)), Backcompat test (cmd/frontend), Backcompat test (cmd/frontend (gRPC)), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Backcompat test (dev/sg), Backcompat test (dev/sg (gRPC)), Backcompat test (internal/database), Backcompat test (enterprise/internal/database)
- **CI script tests**: test-trace-command.sh
- **Integration tests**: Backend integration tests, Code Intel QA
- **Integration tests**: Backend integration tests (gRPC), Backend integration tests, Code Intel QA
- **End-to-end tests**: Executors E2E, Sourcegraph E2E, Sourcegraph QA, Sourcegraph Cluster (deploy-sourcegraph) QA, Sourcegraph Upgrade
- **Publish images**: alpine-3.14, cadvisor, codeinsights-db, codeintel-db, frontend, github-proxy, gitserver, grafana, indexed-searcher, jaeger-agent, jaeger-all-in-one, blobstore, blobstore2, node-exporter, postgres-12-alpine, postgres_exporter, precise-code-intel-worker, prometheus, prometheus-gcp, redis-cache, redis-store, redis_exporter, repo-updater, search-indexer, searcher, symbols, syntax-highlighter, worker, migrator, executor, executor-vm, batcheshelper, opentelemetry-collector, server, sg
- Upload build trace
@ -353,8 +353,9 @@ Base pipeline (more steps might be included based on branch changes):
- **Metadata**: Pipeline metadata
- Build server
- Backend integration tests (gRPC)
- Backend integration tests
- **Linters and static analysis**: Run sg lint
- **Go checks**: Test (all), Test (enterprise/internal/insights), Test (internal/database), Test (internal/repos), Test (enterprise/internal/batches), Test (cmd/frontend), Test (enterprise/internal/database), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (dev/sg), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (enterprise/internal/insights), Backcompat test (internal/database), Backcompat test (internal/repos), Backcompat test (enterprise/internal/batches), Backcompat test (cmd/frontend), Backcompat test (enterprise/internal/database), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (dev/sg)
- **Go checks**: Test (all), Test (all (gRPC)), Test (enterprise/internal/insights), Test (enterprise/internal/insights (gRPC)), Test (internal/repos), Test (internal/repos (gRPC)), Test (enterprise/internal/batches), Test (enterprise/internal/batches (gRPC)), Test (cmd/frontend), Test (cmd/frontend (gRPC)), Test (enterprise/cmd/frontend/internal/batches/resolvers), Test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Test (dev/sg), Test (dev/sg (gRPC)), Test (internal/database), Test (enterprise/internal/database), Build
- **DB backcompat tests**: Backcompat test (all), Backcompat test (all (gRPC)), Backcompat test (enterprise/internal/insights), Backcompat test (enterprise/internal/insights (gRPC)), Backcompat test (internal/repos), Backcompat test (internal/repos (gRPC)), Backcompat test (enterprise/internal/batches), Backcompat test (enterprise/internal/batches (gRPC)), Backcompat test (cmd/frontend), Backcompat test (cmd/frontend (gRPC)), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers), Backcompat test (enterprise/cmd/frontend/internal/batches/resolvers (gRPC)), Backcompat test (dev/sg), Backcompat test (dev/sg (gRPC)), Backcompat test (internal/database), Backcompat test (enterprise/internal/database)
- Upload build trace

View File

@ -436,9 +436,8 @@ func frontendTests(pipeline *bk.Pipeline) {
// Adds the Go test step.
func addGoTests(pipeline *bk.Pipeline) {
buildGoTests(func(description, testSuffix string) {
pipeline.AddStep(
fmt.Sprintf(":go: Test (%s)", description),
buildGoTests(func(description, testSuffix string, additionalOpts ...bk.StepOpt) {
opts := []bk.StepOpt{
// Max DB connections is set to 200: https://github.com/sourcegraph/infrastructure/blob/main/docker-images/buildkite-agent-stateless/postgresql.conf
// Because we run tests concurrently, the following must hold to avoid connection issues:
//
@ -451,6 +450,12 @@ func addGoTests(pipeline *bk.Pipeline) {
Annotations: &bk.AnnotationOpts{},
}),
bk.Cmd("./dev/ci/codecov.sh -c -F go"),
}
opts = append(opts, additionalOpts...)
pipeline.AddStep(
fmt.Sprintf(":go: Test (%s)", description),
opts...,
)
})
}
@ -458,7 +463,7 @@ func addGoTests(pipeline *bk.Pipeline) {
// Adds the Go backcompat test step.
func addGoTestsBackcompat(minimumUpgradeableVersion string) func(pipeline *bk.Pipeline) {
return func(pipeline *bk.Pipeline) {
buildGoTests(func(description, testSuffix string) {
buildGoTests(func(description, testSuffix string, additionalOpts ...bk.StepOpt) {
pipeline.AddStep(
fmt.Sprintf(":go::postgres: Backcompat test (%s)", description),
bk.Env("MINIMUM_UPGRADEABLE_VERSION", minimumUpgradeableVersion),
@ -474,23 +479,41 @@ func addGoTestsBackcompat(minimumUpgradeableVersion string) func(pipeline *bk.Pi
// be run as part of complete coverage. The description will be the specific test path
// broken out to be run independently (or "all"), and the testSuffix will be the string
// to pass to go test to filter test packaes (e.g., "only <pkg>" or "exclude <pkgs...>").
func buildGoTests(f func(description, testSuffix string)) {
func buildGoTests(f func(description, testSuffix string, additionalOpts ...bk.StepOpt)) {
// This is a bandage solution to speed up the go tests by running the slowest ones
// concurrently. As a results, the PR time affecting only Go code is divided by two.
slowGoTestPackages := []string{
// These are the slow packages that we do not want to run twice (once with gRPC, once without).
slowGoTestPackagesNonGRPC := []string{
"github.com/sourcegraph/sourcegraph/internal/database", // 253s
"github.com/sourcegraph/sourcegraph/enterprise/internal/database", // 94s
}
// These are the slow packages that we _do_ want to run twice (once with gRPC, once without).
slowGoTestPackagesGRPC := []string{
"github.com/sourcegraph/sourcegraph/enterprise/internal/insights", // 82+162s
"github.com/sourcegraph/sourcegraph/internal/database", // 253s
"github.com/sourcegraph/sourcegraph/internal/repos", // 106s
"github.com/sourcegraph/sourcegraph/enterprise/internal/batches", // 52 + 60
"github.com/sourcegraph/sourcegraph/cmd/frontend", // 100s
"github.com/sourcegraph/sourcegraph/enterprise/internal/database", // 94s
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/batches/resolvers", // 152s
"github.com/sourcegraph/sourcegraph/dev/sg", // small, but much more practical to have it in its own job
}
f("all", "exclude "+strings.Join(slowGoTestPackages, " "))
allSlowPackages := append(slowGoTestPackagesGRPC, slowGoTestPackagesGRPC...)
enableGRPCEnvOpt := bk.Env("SG_FEATURE_FLAG_GRPC", "true")
for _, slowPkg := range slowGoTestPackages {
// Run all tests that aren't slow both with and without gRPC enabled
f("all", fmt.Sprintf("exclude %s", strings.Join(allSlowPackages, " ")))
f("all (gRPC)", fmt.Sprintf("exclude %s", strings.Join(allSlowPackages, " ")), enableGRPCEnvOpt)
// Run most slow packages both with and without gRPC
for _, slowPkg := range slowGoTestPackagesGRPC {
f(strings.ReplaceAll(slowPkg, "github.com/sourcegraph/sourcegraph/", ""), "only "+slowPkg)
f(strings.ReplaceAll(slowPkg, "github.com/sourcegraph/sourcegraph/", "")+" (gRPC)", "only "+slowPkg, enableGRPCEnvOpt)
}
// These packages won't benefit from duplicating the tests with gRPC enabled, so only run them once.
for _, slowPkg := range slowGoTestPackagesNonGRPC {
f(strings.ReplaceAll(slowPkg, "github.com/sourcegraph/sourcegraph/", ""), "only "+slowPkg)
}
}
@ -507,13 +530,21 @@ func addGoBuild(pipeline *bk.Pipeline) {
// Runtime: ~11m
func backendIntegrationTests(candidateImageTag string) operations.Operation {
return func(pipeline *bk.Pipeline) {
pipeline.AddStep(":chains: Backend integration tests",
// Run tests against the candidate server image
bk.DependsOn(candidateImageStepKey("server")),
bk.Env("IMAGE",
images.DevRegistryImage("server", candidateImageTag)),
bk.Cmd("dev/ci/integration/backend/run.sh"),
bk.ArtifactPaths("./*.log"))
for _, enableGRPC := range []bool{true, false} {
description := ":chains: Backend integration tests"
if enableGRPC {
description += " (gRPC)"
}
pipeline.AddStep(
description,
// Run tests against the candidate server image
bk.DependsOn(candidateImageStepKey("server")),
bk.Env("IMAGE",
images.DevRegistryImage("server", candidateImageTag)),
bk.Env("SG_FEATURE_FLAG_GRPC", strconv.FormatBool(enableGRPC)),
bk.Cmd("dev/ci/integration/backend/run.sh"),
bk.ArtifactPaths("./*.log"))
}
}
}

View File

@ -31,18 +31,17 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
sglog "github.com/sourcegraph/log"
"github.com/sourcegraph/go-diff/diff"
sglog "github.com/sourcegraph/log"
"github.com/sourcegraph/sourcegraph/internal/actor"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/authz"
"github.com/sourcegraph/sourcegraph/internal/conf"
"github.com/sourcegraph/sourcegraph/internal/featureflag"
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
"github.com/sourcegraph/sourcegraph/internal/gitserver/protocol"
proto "github.com/sourcegraph/sourcegraph/internal/gitserver/v1"
internalgrpc "github.com/sourcegraph/sourcegraph/internal/grpc"
"github.com/sourcegraph/sourcegraph/internal/grpc/defaults"
"github.com/sourcegraph/sourcegraph/internal/grpc/streamio"
"github.com/sourcegraph/sourcegraph/internal/httpcli"
@ -586,7 +585,7 @@ func (c *RemoteGitCommand) sendExec(ctx context.Context) (_ io.ReadCloser, errRe
return nil, err
}
if featureflag.FromContext(ctx).GetBoolOr("grpc", false) {
if internalgrpc.IsGRPCEnabled(ctx) {
req := &proto.ExecRequest{
Repo: string(repoName),
EnsureRevision: c.EnsureRevision(),
@ -613,7 +612,6 @@ func (c *RemoteGitCommand) sendExec(ctx context.Context) (_ io.ReadCloser, errRe
r := streamio.NewReader(func() ([]byte, error) {
msg, err := stream.Recv()
if err != nil {
return nil, err
}
return msg.GetData(), nil

View File

@ -2,12 +2,17 @@
package grpc
import (
"context"
"net/http"
"os"
"strconv"
"strings"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"google.golang.org/grpc"
"github.com/sourcegraph/sourcegraph/internal/featureflag"
)
// MultiplexHandlers takes a gRPC server and a plain HTTP handler and multiplexes the
@ -27,3 +32,12 @@ func MultiplexHandlers(grpcServer *grpc.Server, httpHandler http.Handler) http.H
// h2s protocol, so this hijacks h2s requests and handles them correctly.
return h2c.NewHandler(newHandler, &http2.Server{})
}
const envGRPCEnabled = "SG_FEATURE_FLAG_GRPC"
func IsGRPCEnabled(ctx context.Context) bool {
if val, err := strconv.ParseBool(os.Getenv(envGRPCEnabled)); err == nil {
return val
}
return featureflag.FromContext(ctx).GetBoolOr("grpc", false)
}

View File

@ -2,6 +2,7 @@ package grpc
import (
"bytes"
"context"
"net/http"
"net/http/httptest"
"testing"
@ -37,3 +38,20 @@ func TestMultiplexHandlers(t *testing.T) {
require.False(t, called)
}
}
func TestIsGRPCEnabled(t *testing.T) {
t.Setenv(envGRPCEnabled, "true")
if !IsGRPCEnabled(context.Background()) {
t.Fatal("expected grpc to be enabled")
}
t.Setenv(envGRPCEnabled, "false")
if IsGRPCEnabled(context.Background()) {
t.Fatal("expected grpc to not be enabled")
}
t.Setenv(envGRPCEnabled, "")
if IsGRPCEnabled(context.Background()) {
t.Fatal("expected grpc to not be enabled")
}
}

View File

@ -15,8 +15,8 @@ import (
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/endpoint"
"github.com/sourcegraph/sourcegraph/internal/errcode"
"github.com/sourcegraph/sourcegraph/internal/featureflag"
"github.com/sourcegraph/sourcegraph/internal/gitserver"
internalgrpc "github.com/sourcegraph/sourcegraph/internal/grpc"
"github.com/sourcegraph/sourcegraph/internal/mutablelimiter"
"github.com/sourcegraph/sourcegraph/internal/search"
"github.com/sourcegraph/sourcegraph/internal/search/job"
@ -197,7 +197,7 @@ func (s *TextSearchJob) searchFilesInRepo(
return false, err
}
if featureflag.FromContext(ctx).GetBoolOr("grpc", false) {
if internalgrpc.IsGRPCEnabled(ctx) {
onMatches := func(searcherMatch *proto.FileMatch) {
stream.Send(streaming.SearchEvent{
Results: []result.Match{convertProtoMatch(repo, commit, &rev, searcherMatch, s.PathRegexps)},
@ -219,7 +219,7 @@ func (s *TextSearchJob) searchFilesInRepo(
})
}
if featureflag.FromContext(ctx).GetBoolOr("grpc", false) {
if internalgrpc.IsGRPCEnabled(ctx) {
return SearchGRPC(ctx, searcherURLs, gitserverRepo, repo.ID, rev, commit, index, info, fetchTimeout, s.Features, onMatchGRPC)
} else {
return Search(ctx, searcherURLs, gitserverRepo, repo.ID, rev, commit, index, info, fetchTimeout, s.Features, onMatches)

View File

@ -23,7 +23,7 @@ import (
"github.com/sourcegraph/sourcegraph/internal/authz"
"github.com/sourcegraph/sourcegraph/internal/conf/conftypes"
"github.com/sourcegraph/sourcegraph/internal/endpoint"
"github.com/sourcegraph/sourcegraph/internal/featureflag"
internalgrpc "github.com/sourcegraph/sourcegraph/internal/grpc"
"github.com/sourcegraph/sourcegraph/internal/grpc/defaults"
"github.com/sourcegraph/sourcegraph/internal/httpcli"
"github.com/sourcegraph/sourcegraph/internal/resetonce"
@ -93,7 +93,7 @@ func (c *Client) ListLanguageMappings(ctx context.Context, repo api.RepoName) (_
c.langMappingOnce.Do(func() {
var mappings map[string][]string
if c.isGRPCEnabled(ctx) {
if internalgrpc.IsGRPCEnabled(ctx) {
mappings, err = c.listLanguageMappingsGRPC(ctx, repo)
} else {
mappings, err = c.listLanguageMappingsJSON(ctx, repo)
@ -192,7 +192,7 @@ func (c *Client) Search(ctx context.Context, args search.SymbolsParameters) (sym
var response search.SymbolsResponse
if c.isGRPCEnabled(ctx) {
if internalgrpc.IsGRPCEnabled(ctx) {
response, err = c.searchGRPC(ctx, args)
} else {
response, err = c.searchJSON(ctx, args)
@ -298,7 +298,7 @@ func (c *Client) LocalCodeIntel(ctx context.Context, args types.RepoCommitPath)
span.SetTag("Repo", args.Repo)
span.SetTag("CommitID", args.Commit)
if c.isGRPCEnabled(ctx) {
if internalgrpc.IsGRPCEnabled(ctx) {
return c.localCodeIntelGRPC(ctx, args)
}
@ -365,7 +365,7 @@ func (c *Client) SymbolInfo(ctx context.Context, args types.RepoCommitPathPoint)
span.SetTag("Repo", args.Repo)
span.SetTag("CommitID", args.Commit)
if c.isGRPCEnabled(ctx) {
if internalgrpc.IsGRPCEnabled(ctx) {
result, err = c.symbolInfoGRPC(ctx, args)
} else {
result, err = c.symbolInfoJSON(ctx, args)
@ -528,7 +528,3 @@ func (c *Client) dialGRPC(ctx context.Context, repository api.RepoName) (*grpc.C
return conn, nil
}
func (c *Client) isGRPCEnabled(ctx context.Context) bool {
return featureflag.FromContext(ctx).GetBoolOr("grpc", false)
}

View File

@ -7,12 +7,21 @@ import (
"net/http/httptest"
"testing"
"github.com/sourcegraph/log"
"github.com/sourcegraph/log/logtest"
"google.golang.org/grpc"
"github.com/sourcegraph/sourcegraph/internal/actor"
"github.com/sourcegraph/sourcegraph/internal/authz"
"github.com/sourcegraph/sourcegraph/internal/endpoint"
internalgrpc "github.com/sourcegraph/sourcegraph/internal/grpc"
"github.com/sourcegraph/sourcegraph/internal/grpc/defaults"
"github.com/sourcegraph/sourcegraph/internal/search"
"github.com/sourcegraph/sourcegraph/internal/search/result"
"github.com/sourcegraph/sourcegraph/internal/types"
"github.com/sourcegraph/sourcegraph/lib/errors"
proto "github.com/sourcegraph/sourcegraph/internal/symbols/v1"
)
func init() {
@ -32,12 +41,27 @@ func TestSearchWithFiltering(t *testing.T) {
Path: "file2",
},
}}
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(fixture)
}))
mockServer := &mockSymbolsServer{
mockSearchGRPC: func(_ context.Context, _ *proto.SearchRequest) (*proto.SearchResponse, error) {
var response proto.SearchResponse
response.FromInternal(&fixture)
return &response, nil
},
restHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(fixture)
}),
}
handler, cleanup := mockServer.NewHandler(logtest.Scoped(t))
srv := httptest.NewServer(handler)
t.Cleanup(func() {
srv.Close()
cleanup()
})
DefaultClient.Endpoints = endpoint.Static(srv.URL)
results, err := DefaultClient.Search(ctx, search.SymbolsParameters{
@ -111,16 +135,34 @@ func TestDefinitionWithFiltering(t *testing.T) {
Point: types.Point{Row: 0, Column: 0},
}
// Start an HTTP server that responds with path1.
ctx := context.Background()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(path1)
}))
mockServer := &mockSymbolsServer{
mockSymbolInfoGRPC: func(_ context.Context, _ *proto.SymbolInfoRequest) (*proto.SymbolInfoResponse, error) {
var info types.SymbolInfo
info.Definition.RepoCommitPath = path1.RepoCommitPath
var response proto.SymbolInfoResponse
response.FromInternal(&info)
return &response, nil
},
restHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(path1)
}),
}
// Create a new HTTP server that response with path1.
handler, cleanup := mockServer.NewHandler(logtest.Scoped(t))
srv := httptest.NewServer(handler)
t.Cleanup(func() {
srv.Close()
cleanup()
})
DefaultClient.Endpoints = endpoint.Static(srv.URL)
ctx := context.Background()
// Request path1.
results, err := DefaultClient.SymbolInfo(ctx, path2)
if err != nil {
@ -152,3 +194,81 @@ func TestDefinitionWithFiltering(t *testing.T) {
t.Fatal("expected nil result when getting a definition for an unauthorized path")
}
}
type mockSymbolsServer struct {
mockSearchGRPC func(ctx context.Context, request *proto.SearchRequest) (*proto.SearchResponse, error)
mockLocalCodeIntelGRPC func(ctx context.Context, request *proto.LocalCodeIntelRequest) (*proto.LocalCodeIntelResponse, error)
mockListLanguagesGRPC func(ctx context.Context, request *proto.ListLanguagesRequest) (*proto.ListLanguagesResponse, error)
mockSymbolInfoGRPC func(ctx context.Context, request *proto.SymbolInfoRequest) (*proto.SymbolInfoResponse, error)
mockHealthzGRPC func(ctx context.Context, request *proto.HealthzRequest) (*proto.HealthzResponse, error)
restHandler http.Handler
proto.UnimplementedSymbolsServiceServer
}
func (m *mockSymbolsServer) NewHandler(l log.Logger) (handler http.Handler, cleanup func()) {
grpcServer := grpc.NewServer(
defaults.ServerOptions(l)...,
)
grpcServer.RegisterService(&proto.SymbolsService_ServiceDesc, m)
handler = internalgrpc.MultiplexHandlers(grpcServer, http.HandlerFunc(m.serveRestHandler))
cleanup = func() {
grpcServer.Stop()
}
return handler, cleanup
}
func (m *mockSymbolsServer) serveRestHandler(w http.ResponseWriter, r *http.Request) {
if m.restHandler != nil {
m.restHandler.ServeHTTP(w, r)
return
}
http.Error(w, "not implemented", http.StatusNotImplemented)
}
func (m *mockSymbolsServer) Search(ctx context.Context, r *proto.SearchRequest) (*proto.SearchResponse, error) {
if m.mockSearchGRPC != nil {
return m.mockSearchGRPC(ctx, r)
}
return nil, errors.Newf("grpc: method %q not implemented", "Search")
}
func (m *mockSymbolsServer) LocalCodeIntel(ctx context.Context, r *proto.LocalCodeIntelRequest) (*proto.LocalCodeIntelResponse, error) {
if m.mockLocalCodeIntelGRPC != nil {
return m.LocalCodeIntel(ctx, r)
}
return nil, errors.Newf("grpc: method %q not implemented", "LocalCodeIntel")
}
func (m *mockSymbolsServer) ListLanguages(ctx context.Context, r *proto.ListLanguagesRequest) (*proto.ListLanguagesResponse, error) {
if m.mockListLanguagesGRPC != nil {
return m.mockListLanguagesGRPC(ctx, r)
}
return nil, errors.Newf("grpc: method %q not implemented", "ListLanguages")
}
func (m *mockSymbolsServer) SymbolInfo(ctx context.Context, r *proto.SymbolInfoRequest) (*proto.SymbolInfoResponse, error) {
if m.mockSymbolInfoGRPC != nil {
return m.mockSymbolInfoGRPC(ctx, r)
}
return nil, errors.Newf("grpc: method %q not implemented", "SymbolInfo")
}
func (m *mockSymbolsServer) Healthz(ctx context.Context, r *proto.HealthzRequest) (*proto.HealthzResponse, error) {
if m.mockHealthzGRPC != nil {
return m.mockHealthzGRPC(ctx, r)
}
return nil, errors.Newf("grpc: method %q not implemented", "Healthz")
}
var _ proto.SymbolsServiceServer = &mockSymbolsServer{}