Skip to content

Commit

Permalink
Merge branch 'main' into docs/update-router-terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
Meschreiber authored Jul 10, 2024
2 parents d544a7a + 880b307 commit 02514bb
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 91 deletions.
28 changes: 24 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ workflows:
rust_channel: [stable]
command: [test]

- xtask:
name: Run studio integration tests on GitHub (<< matrix.rust_channel >> rust on << matrix.platform >>)
context:
- github-orb
matrix:
parameters:
platform: [amd_ubuntu]
rust_channel: [stable]
command: [github-actions]
options:
- |
--workflow-name 'tests-mac-x86.yml' --branch "<< pipeline.git.branch >>" --commit-id "<< pipeline.git.revision >>" --inputs '{"composition-versions": "[\"2.8.2\"]", "router-versions": "[\"1.50.0\"]"}'
- xtask:
name: Run supergraph-demo tests (<< matrix.rust_channel >> rust on << matrix.platform >>)
matrix:
Expand Down Expand Up @@ -247,7 +260,7 @@ jobs:
type: executor
command:
type: enum
enum: [lint, unit-test, integration-test, test, package, security-checks]
enum: [lint, unit-test, integration-test, test, package, security-checks, github-actions]
options:
type: string
default: ""
Expand Down Expand Up @@ -508,14 +521,21 @@ commands:
parameters:
command:
type: enum
enum: [lint, integration-test, unit-test, test, package, security-checks]
enum: [lint, integration-test, unit-test, test, package, security-checks, github-actions]
options:
type: string
platform:
type: executor
steps:
- run:
command: cargo xtask << parameters.command >> << parameters.options >>
command: |
export GITHUB_ACTIONS_TOKEN="$(echo "$GH_BOT_KEY_B64" | base64 -d)"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_ACTIONS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/user
cargo xtask << parameters.command >> << parameters.options >>
- unless:
condition:
Expand Down Expand Up @@ -663,4 +683,4 @@ commands:
steps:
- run:
name: Publish to npm (beta)
command: cd << parameters.npm_dir >> && npm publish --tag beta << parameters.options >>
command: cd << parameters.npm_dir >> && npm publish --tag beta << parameters.options >>
8 changes: 7 additions & 1 deletion .circleci/scripts/install_npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
set -euo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
INSTALLERS_DIR="$SCRIPT_DIR/../../installers/npm"

cd "$(mktemp -d)"
echo "Created test directory"
npm init -y
echo "Initialised new npm package"
npm install --install-links=true "$SCRIPT_DIR/../../installers/npm"
# The choice of version here is arbitrary (we just need something we know exists) so that we can test if the
# installer works, given an existing version. This way we're not at the mercy of whether the binary that corresponds
# to the latest commit exists.
npm --prefix "$INSTALLERS_DIR" version --allow-same-version 0.23.0
echo "Temporarily patched package.json to fixed stable binary"
npm install --install-links=true "$INSTALLERS_DIR"
echo "Installed rover as local npm package"
cd node_modules/.bin/
echo "Checking version"
Expand Down
8 changes: 7 additions & 1 deletion .circleci/scripts/install_npm_global.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
set -euo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
INSTALLERS_DIR="$SCRIPT_DIR/../../installers/npm"

cd "$(mktemp -d)"
echo "Created test directory"
npm install --install-links=true -g "$SCRIPT_DIR/../../installers/npm"
# The choice of version here is arbitrary (we just need something we know exists) so that we can test if the
# installer works, given an existing version. This way we're not at the mercy of whether the binary that corresponds
# to the latest commit exists.
npm version --prefix="$INSTALLERS_DIR" --allow-same-version 0.23.0
echo "Temporarily patched package.json to fixed stable binary"
npm install --install-links=true -g "$INSTALLERS_DIR"
echo "Installed rover as global npm package"
cd /usr/local/bin/
echo "Checking version"
Expand Down
6 changes: 6 additions & 0 deletions .circleci/scripts/install_pnpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
set -euo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
INSTALLERS_DIR="$SCRIPT_DIR/../../installers/npm"

cd "$(mktemp -d)"
echo "Created test directory"
npm install -g [email protected]
echo "Installed pnpm"
# The choice of version here is arbitrary (we just need something we know exists) so that we can test if the
# installer works, given an existing version. This way we're not at the mercy of whether the binary that corresponds
# to the latest commit exists.
npm --prefix "$INSTALLERS_DIR" version --allow-same-version 0.23.0
echo "Temporarily patched package.json to fixed stable binary"
pnpm init
pnpm add "file:$SCRIPT_DIR/../../installers/npm"
echo "Installed rover as pnpm package"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-mac-x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
matrix:
composition-version: ${{ fromJSON(inputs.composition-versions) }}
# x86-64 runner
runs-on: macos-13
runs-on: macos-14-large
env:
TEST_COMPOSITION_VERSION: "=${{ matrix.composition-version }}"
ROVER_BINARY: ../../artifact/rover
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ notify = { workspace = true }
opener = { workspace = true }
os_info = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true, features = ["blocking", "json"] }
robot-panic = { workspace = true }
rover-client = { workspace = true }
Expand Down
40 changes: 10 additions & 30 deletions installers/npm/tests/binary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ const crypto = require("node:crypto");
const MockAdapter = require("axios-mock-adapter");
const axios = require("axios");

var mock = new MockAdapter(axios);
mock.onGet(new RegExp("https://rover\.apollo\.dev.*")).reply(function (_) {
return [
200,
fs.createReadStream(
path.join(__dirname, "fake_tarballs", "rover-fake.tar.gz"),
),
];
});

test("getBinary should be created with correct name and URL", () => {
fs.mkdtempSync(path.join(os.tmpdir(), "rover-tests-"));
const bin = binary.getBinary(os.tmpdir());
Expand Down Expand Up @@ -83,16 +93,6 @@ test("install recreates an existing directory if it exists", () => {
});

test("install downloads a binary if none exists", async () => {
// Setup Axios mocking
var mock = new MockAdapter(axios);
mock.onGet(new RegExp("https://rover.apollo.dev.*")).reply(function (_) {
return [
200,
fs.createReadStream(
path.join(__dirname, "fake_tarballs", "rover-fake.tar.gz"),
),
];
});
// Create temporary directory and binary
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "rover-tests-"));
const bin = binary.getBinary(directory);
Expand All @@ -115,16 +115,6 @@ test("install downloads a binary if none exists", async () => {
});

test("install renames binary properly", async () => {
// Setup mocking
var mock = new MockAdapter(axios);
mock.onGet(new RegExp("https://rover.apollo.dev.*")).reply(function (_) {
return [
200,
fs.createReadStream(
path.join(__dirname, "fake_tarballs", "rover-fake.tar.gz"),
),
];
});
// Establish temporary directory
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "rover-tests-"));
// Create a Binary object
Expand All @@ -140,16 +130,6 @@ test("install renames binary properly", async () => {
});

test("install adds a new binary if another version exists", async () => {
// Setup mocking for Axios
var mock = new MockAdapter(axios);
mock.onGet(new RegExp("https://rover.apollo.dev.*")).reply(function (_) {
return [
200,
fs.createReadStream(
path.join(__dirname, "fake_tarballs", "rover-fake.tar.gz"),
),
];
});
// Create the temporary directory
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "rover-tests-"));
// Put a fake binary into that directory, so it looks like one has been downloaded before
Expand Down
28 changes: 24 additions & 4 deletions src/command/dev/protocol/leader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct LeaderSession {
follower_channel: FollowerChannel,
leader_channel: LeaderChannel,
federation_version: FederationVersion,
supergraph_config: Option<SupergraphConfig>,
}

impl LeaderSession {
Expand Down Expand Up @@ -141,6 +142,7 @@ impl LeaderSession {
follower_channel,
leader_channel,
federation_version,
supergraph_config: supergraph_config.clone(),
}))
}

Expand Down Expand Up @@ -267,6 +269,23 @@ impl LeaderSession {

if let Vacant(e) = self.subgraphs.entry((name.to_string(), url.clone())) {
e.insert(sdl.to_string());

// Followers add subgraphs, but sometimes those subgraphs depend on each other
// (e.g., through extending a type in another subgraph). When that happens,
// composition fails until _all_ subgraphs are loaded in. This acknowledges the
// follower's message when we haven't loaded in all the subgraphs, deferring
// composition until we have at least the number of subgraphs represented in the
// supergraph.yaml file
//
// This applies only when the supergraph.yaml file is present. Without it, we will
// try composition each time we add a subgraph
if let Some(supergraph_config) = self.supergraph_config.clone() {
let subgraphs_from_config = supergraph_config.into_iter();
if self.subgraphs.len() < subgraphs_from_config.len() {
return LeaderMessageKind::MessageReceived;
}
}

let composition_result = self.compose();
if let Err(composition_err) = composition_result {
LeaderMessageKind::error(composition_err)
Expand Down Expand Up @@ -335,7 +354,7 @@ impl LeaderSession {
/// Reruns composition, which triggers the router to reload.
fn compose(&mut self) -> CompositionResult {
self.compose_runner
.run(&mut self.supergraph_config())
.run(&mut self.supergraph_config_internal_representation())
.and_then(|maybe_new_schema| {
if maybe_new_schema.is_some() {
if let Err(err) = self.router_runner.spawn() {
Expand Down Expand Up @@ -374,9 +393,10 @@ impl LeaderSession {
socket_write(&message, stream)
}

/// Gets the supergraph configuration from the internal state.
/// Calling `.to_string()` on a [`SupergraphConfig`] writes
fn supergraph_config(&self) -> SupergraphConfig {
/// Gets the supergraph configuration from the internal state. This can different from the
/// supergraph.yaml file as it represents intermediate states of composition while adding
/// subgraphs to the internal representation of that file
fn supergraph_config_internal_representation(&self) -> SupergraphConfig {
let mut supergraph_config: SupergraphConfig = self
.subgraphs
.iter()
Expand Down
Loading

0 comments on commit 02514bb

Please sign in to comment.