Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 35f1b21

Browse files
committedNov 12, 2024·
Migrate to GitHub Actions
Migrate CI to use GitHub Actions. Motivation: To migrate to GitHub actions and centralised infrastructure. Modifications: Changes of note: * Bump minimum Swift version to 5.9 in line with CI coverage. * Adopt NIO formatting rules * Remove scripts and docker files which are no longer needed. * Fixup minor changes in `NIOAsyncChannel` API usage Result: Feature parity with old CI plus additional soundness checks.
1 parent c63219e commit 35f1b21

25 files changed

+514
-68
lines changed
 

‎.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true

‎.github/release.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
changelog:
2+
categories:
3+
- title: SemVer Major
4+
labels:
5+
- ⚠️ semver/major
6+
- title: SemVer Minor
7+
labels:
8+
- semver/minor
9+
- title: SemVer Patch
10+
labels:
11+
- semver/patch
12+
- title: Other Changes
13+
labels:
14+
- semver/none

‎.github/workflows/benchmarks.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Unit tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
benchmark_package_path:
7+
type: string
8+
description: "Path to the directory containing the benchmarking package. Defaults to ."
9+
default: "."
10+
swift_package_arguments:
11+
type: string
12+
description: "Arguments to the switch package command invocation e.g. `--disable-sandbox`"
13+
linux_5_9_enabled:
14+
type: boolean
15+
description: "Boolean to enable the Linux 5.9 Swift version matrix job. Defaults to true."
16+
default: true
17+
linux_5_10_enabled:
18+
type: boolean
19+
description: "Boolean to enable the Linux 5.10 Swift version matrix job. Defaults to true."
20+
default: true
21+
linux_6_0_enabled:
22+
type: boolean
23+
description: "Boolean to enable the Linux 6.0 Swift version matrix job. Defaults to true."
24+
default: true
25+
linux_nightly_6_0_enabled:
26+
type: boolean
27+
description: "Boolean to enable the Linux nightly 6.0 Swift version matrix job. Defaults to true."
28+
default: true
29+
linux_nightly_main_enabled:
30+
type: boolean
31+
description: "Boolean to enable the Linux nightly main Swift version matrix job. Defaults to true."
32+
default: true
33+
34+
jobs:
35+
unit-tests:
36+
name: Unit tests
37+
runs-on: ubuntu-latest
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
# We are specifying only the major and minor of the docker images to automatically pick up the latest patch release
42+
swift:
43+
- image: "swift:5.9-jammy"
44+
swift_version: "5.9"
45+
enabled: ${{ inputs.linux_5_9_enabled }}
46+
- image: "swift:5.10-jammy"
47+
swift_version: "5.10"
48+
enabled: ${{ inputs.linux_5_10_enabled }}
49+
- image: "swift:6.0-jammy"
50+
swift_version: "6.0"
51+
enabled: ${{ inputs.linux_6_0_enabled }}
52+
- image: "swiftlang/swift:nightly-6.0-jammy"
53+
swift_version: "nightly-6.0"
54+
enabled: ${{ inputs.linux_nightly_6_0_enabled }}
55+
- image: "swiftlang/swift:nightly-main-jammy"
56+
swift_version: "nightly-main"
57+
enabled: ${{ inputs.linux_nightly_main_enabled }}
58+
steps:
59+
- name: Checkout repository
60+
if: ${{ matrix.swift.enabled }}
61+
uses: actions/checkout@v4
62+
with:
63+
persist-credentials: false
64+
submodules: true
65+
- name: Mark the workspace as safe
66+
if: ${{ matrix.swift.enabled }}
67+
# https://github.com/actions/checkout/issues/766
68+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
69+
- name: Run matrix job
70+
if: ${{ matrix.swift.enabled }}
71+
env:
72+
SWIFT_VERSION: ${{ matrix.swift.swift_version }}
73+
COMMAND: "apt-get update -y -q && apt-get install -y -q libjemalloc-dev && swift package --package-path ${{ inputs.benchmark_package_path }} ${{ inputs.swift_package_arguments }} benchmark baseline check --check-absolute-path ${{ inputs.benchmark_package_path }}/Thresholds/${SWIFT_VERSION}/"
74+
COMMAND_OVERRIDE_5_9: ""
75+
COMMAND_OVERRIDE_5_10: ""
76+
COMMAND_OVERRIDE_6_0: ""
77+
COMMAND_OVERRIDE_NIGHTLY_6_0: ""
78+
COMMAND_OVERRIDE_NIGHTLY_MAIN: ""
79+
run: |
80+
apt-get -qq update && apt-get -qq -y install curl
81+
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.sh | bash
82+
container:
83+
image: ${{ matrix.swift.image }}
84+
services:
85+
memcached:
86+
image: memcached:latest

‎.github/workflows/main.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches: [main]
6+
schedule:
7+
- cron: "0 8,20 * * *"
8+
9+
jobs:
10+
unit-tests:
11+
name: Unit tests
12+
uses: ./.github/workflows/unit_tests.yml
13+
with:
14+
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -strict-concurrency=complete"
15+
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -strict-concurrency=complete"
16+
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
17+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
18+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
19+
20+
benchmarks:
21+
name: Benchmarks
22+
uses: apple/swift-nio/.github/workflows/benchmarks.yml@main
23+
with:
24+
benchmark_package_path: "Benchmarks"

‎.github/workflows/pull_request.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
soundness:
9+
name: Soundness
10+
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
11+
with:
12+
license_header_check_project_name: "swift-memcache-gsoc"
13+
14+
unit-tests:
15+
name: Unit tests
16+
uses: ./.github/workflows/unit_tests.yml
17+
with:
18+
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -strict-concurrency=complete"
19+
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -strict-concurrency=complete"
20+
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
21+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
22+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
23+
24+
benchmarks:
25+
name: Benchmarks
26+
uses: apple/swift-nio/.github/workflows/benchmarks.yml@main
27+
with:
28+
benchmark_package_path: "Benchmarks"
29+
30+
cxx-interop:
31+
name: Cxx interop
32+
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: PR label
2+
3+
on:
4+
pull_request:
5+
types: [labeled, unlabeled, opened, reopened, synchronize]
6+
7+
jobs:
8+
semver-label-check:
9+
name: Semantic version label check
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 1
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
with:
16+
persist-credentials: false
17+
- name: Check for Semantic Version label
18+
uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main

‎.github/workflows/unit_tests.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Unit tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
linux_5_9_enabled:
7+
type: boolean
8+
description: "Boolean to enable the Linux 5.9 Swift version matrix job. Defaults to true."
9+
default: true
10+
linux_5_9_arguments_override:
11+
type: string
12+
description: "The arguments passed to swift test in the Linux 5.9 Swift version matrix job."
13+
default: ""
14+
linux_5_10_enabled:
15+
type: boolean
16+
description: "Boolean to enable the Linux 5.10 Swift version matrix job. Defaults to true."
17+
default: true
18+
linux_5_10_arguments_override:
19+
type: string
20+
description: "The arguments passed to swift test in the Linux 5.10 Swift version matrix job."
21+
default: ""
22+
linux_6_0_enabled:
23+
type: boolean
24+
description: "Boolean to enable the Linux 6.0 Swift version matrix job. Defaults to true."
25+
default: true
26+
linux_6_0_arguments_override:
27+
type: string
28+
description: "The arguments passed to swift test in the Linux 6.0 Swift version matrix job."
29+
default: ""
30+
linux_nightly_6_0_enabled:
31+
type: boolean
32+
description: "Boolean to enable the Linux nightly 6.0 Swift version matrix job. Defaults to true."
33+
default: true
34+
linux_nightly_6_0_arguments_override:
35+
type: string
36+
description: "The arguments passed to swift test in the Linux nightly 6.0 Swift version matrix job."
37+
default: ""
38+
linux_nightly_main_enabled:
39+
type: boolean
40+
description: "Boolean to enable the Linux nightly main Swift version matrix job. Defaults to true."
41+
default: true
42+
linux_nightly_main_arguments_override:
43+
type: string
44+
description: "The arguments passed to swift test in the Linux nightly main Swift version matrix job."
45+
default: ""
46+
47+
jobs:
48+
unit-tests:
49+
name: Unit tests
50+
runs-on: ubuntu-latest
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
# We are specifying only the major and minor of the docker images to automatically pick up the latest patch release
55+
swift:
56+
- image: "swift:5.9-jammy"
57+
swift_version: "5.9"
58+
enabled: ${{ inputs.linux_5_9_enabled }}
59+
- image: "swift:5.10-jammy"
60+
swift_version: "5.10"
61+
enabled: ${{ inputs.linux_5_10_enabled }}
62+
- image: "swift:6.0-jammy"
63+
swift_version: "6.0"
64+
enabled: ${{ inputs.linux_6_0_enabled }}
65+
- image: "swiftlang/swift:nightly-6.0-jammy"
66+
swift_version: "nightly-6.0"
67+
enabled: ${{ inputs.linux_nightly_6_0_enabled }}
68+
- image: "swiftlang/swift:nightly-main-jammy"
69+
swift_version: "nightly-main"
70+
enabled: ${{ inputs.linux_nightly_main_enabled }}
71+
steps:
72+
- name: Checkout repository
73+
if: ${{ matrix.swift.enabled }}
74+
uses: actions/checkout@v4
75+
with:
76+
persist-credentials: false
77+
submodules: true
78+
- name: Mark the workspace as safe
79+
if: ${{ matrix.swift.enabled }}
80+
# https://github.com/actions/checkout/issues/766
81+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
82+
- name: Run matrix job
83+
if: ${{ matrix.swift.enabled }}
84+
env:
85+
SWIFT_VERSION: ${{ matrix.swift.swift_version }}
86+
COMMAND: "swift test"
87+
COMMAND_OVERRIDE_5_9: "swift test ${{ inputs.linux_5_9_arguments_override }}"
88+
COMMAND_OVERRIDE_5_10: "swift test ${{ inputs.linux_5_10_arguments_override }}"
89+
COMMAND_OVERRIDE_6_0: "swift test ${{ inputs.linux_6_0_arguments_override }}"
90+
COMMAND_OVERRIDE_NIGHTLY_6_0: "swift test ${{ inputs.linux_nightly_6_0_arguments_override }}"
91+
COMMAND_OVERRIDE_NIGHTLY_MAIN: "swift test ${{ inputs.linux_nightly_main_arguments_override }}"
92+
run: |
93+
apt-get -qq update && apt-get -qq -y install curl
94+
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.sh | bash
95+
container:
96+
image: ${{ matrix.swift.image }}
97+
services:
98+
memcached:
99+
image: memcached:latest

‎.licenseignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.gitignore
2+
**/.gitignore
3+
.licenseignore
4+
.gitattributes
5+
.git-blame-ignore-revs
6+
.mailfilter
7+
.mailmap
8+
.spi.yml
9+
.swift-format
10+
.swiftformatignore
11+
.editorconfig
12+
.github/*
13+
*.md
14+
*.txt
15+
*.yml
16+
*.yaml
17+
*.json
18+
Package.swift
19+
**/Package.swift
20+
Package@-*.swift
21+
**/Package@-*.swift
22+
Package.resolved
23+
**/Package.resolved
24+
Makefile
25+
*.modulemap
26+
**/*.modulemap
27+
**/*.docc/*
28+
*.xcprivacy
29+
**/*.xcprivacy
30+
*.symlink
31+
**/*.symlink
32+
Dockerfile
33+
**/Dockerfile
34+
Snippets/*
35+
dev/git.commit.template
36+
.unacceptablelanguageignore

‎.swift-format

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"version" : 1,
3+
"indentation" : {
4+
"spaces" : 4
5+
},
6+
"tabWidth" : 4,
7+
"fileScopedDeclarationPrivacy" : {
8+
"accessLevel" : "private"
9+
},
10+
"spacesAroundRangeFormationOperators" : false,
11+
"indentConditionalCompilationBlocks" : false,
12+
"indentSwitchCaseLabels" : false,
13+
"lineBreakAroundMultilineExpressionChainComponents" : false,
14+
"lineBreakBeforeControlFlowKeywords" : false,
15+
"lineBreakBeforeEachArgument" : true,
16+
"lineBreakBeforeEachGenericRequirement" : true,
17+
"lineLength" : 120,
18+
"maximumBlankLines" : 1,
19+
"respectsExistingLineBreaks" : true,
20+
"prioritizeKeepingFunctionOutputTogether" : true,
21+
"noAssignmentInExpressions" : {
22+
"allowedFunctions" : [
23+
"XCTAssertNoThrow",
24+
"XCTAssertThrowsError"
25+
]
26+
},
27+
"rules" : {
28+
"AllPublicDeclarationsHaveDocumentation" : false,
29+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
30+
"AlwaysUseLowerCamelCase" : false,
31+
"AmbiguousTrailingClosureOverload" : true,
32+
"BeginDocumentationCommentWithOneLineSummary" : false,
33+
"DoNotUseSemicolons" : true,
34+
"DontRepeatTypeInStaticProperties" : true,
35+
"FileScopedDeclarationPrivacy" : true,
36+
"FullyIndirectEnum" : true,
37+
"GroupNumericLiterals" : true,
38+
"IdentifiersMustBeASCII" : true,
39+
"NeverForceUnwrap" : false,
40+
"NeverUseForceTry" : false,
41+
"NeverUseImplicitlyUnwrappedOptionals" : false,
42+
"NoAccessLevelOnExtensionDeclaration" : true,
43+
"NoAssignmentInExpressions" : true,
44+
"NoBlockComments" : true,
45+
"NoCasesWithOnlyFallthrough" : true,
46+
"NoEmptyTrailingClosureParentheses" : true,
47+
"NoLabelsInCasePatterns" : true,
48+
"NoLeadingUnderscores" : false,
49+
"NoParensAroundConditions" : true,
50+
"NoVoidReturnOnFunctionSignature" : true,
51+
"OmitExplicitReturns" : true,
52+
"OneCasePerLine" : true,
53+
"OneVariableDeclarationPerLine" : true,
54+
"OnlyOneTrailingClosureArgument" : true,
55+
"OrderedImports" : true,
56+
"ReplaceForEachWithForLoop" : true,
57+
"ReturnVoidInsteadOfEmptyTuple" : true,
58+
"UseEarlyExits" : false,
59+
"UseExplicitNilCheckInConditions" : false,
60+
"UseLetInEveryBoundCaseVariable" : false,
61+
"UseShorthandTypeNames" : true,
62+
"UseSingleLinePropertyGetter" : false,
63+
"UseSynthesizedInitializer" : false,
64+
"UseTripleSlashForDocumentationComments" : true,
65+
"UseWhereClausesInForLoops" : false,
66+
"ValidateDocumentationComments" : false
67+
}
68+
}

‎Benchmarks/Benchmarks/MemcacheBenchmarks/MemcacheBenchmarks.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private let eventLoopGroup = MultiThreadedEventLoopGroup.singleton.next()
2121

2222
let benchmarks = {
2323
let defaultMetrics: [BenchmarkMetric] = [
24-
.mallocCountTotal,
24+
.mallocCountTotal
2525
]
2626

2727
Benchmark(
@@ -41,7 +41,10 @@ let benchmarks = {
4141
timeUnits: .milliseconds
4242
)
4343
) { benchmark in
44-
try await runSetWithTTLRequest(iterations: benchmark.scaledIterations.upperBound, eventLoopGroup: eventLoopGroup)
44+
try await runSetWithTTLRequest(
45+
iterations: benchmark.scaledIterations.upperBound,
46+
eventLoopGroup: eventLoopGroup
47+
)
4548
}
4649
Benchmark(
4750
"Delete Request",

‎Benchmarks/Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import PackageDescription
1818
let package = Package(
1919
name: "Benchmarks",
2020
platforms: [
21-
.macOS(.v13),
21+
.macOS(.v13)
2222
],
2323
dependencies: [
2424
.package(name: "swift-memcache-gsoc", path: "../"),
@@ -36,8 +36,8 @@ let package = Package(
3636
],
3737
path: "Benchmarks/MemcacheBenchmarks",
3838
plugins: [
39-
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
39+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
4040
]
41-
),
41+
)
4242
]
4343
)

‎Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.7
1+
// swift-tools-version: 5.9
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the swift-memcache-gsoc open source project
@@ -27,10 +27,10 @@ let package = Package(
2727
.library(
2828
name: "Memcache",
2929
targets: ["Memcache"]
30-
),
30+
)
3131
],
3232
dependencies: [
33-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.56.0"),
33+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.76.1"),
3434
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
3535
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.0.0"),
3636
],
@@ -52,7 +52,7 @@ let package = Package(
5252
.executableTarget(
5353
name: "MemcacheExample",
5454
dependencies: [
55-
.target(name: "Memcache"),
55+
.target(name: "Memcache")
5656
]
5757
),
5858
]

‎Sources/Memcache/Extensions/ByteBuffer+Memcache.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import NIOCore
16+
1517
#if os(Linux)
1618
import Glibc
1719
#else
1820
import Darwin
1921
#endif
20-
import NIOCore
2122

2223
extension ByteBuffer {
2324
/// Write `integer` into this `ByteBuffer` as ASCII digits, without leading zeros, moving the writer index forward appropriately.
@@ -40,7 +41,8 @@ extension ByteBuffer {
4041
mutating func readIntegerFromASCII<T: FixedWidthInteger>() -> T? {
4142
var value: T = 0
4243
while self.readableBytes > 0, let currentByte = self.readInteger(as: UInt8.self),
43-
currentByte >= UInt8.zero && currentByte <= UInt8.nine {
44+
currentByte >= UInt8.zero && currentByte <= UInt8.nine
45+
{
4446
value = (value * 10) + T(currentByte - UInt8.zero)
4547
}
4648
return value > 0 ? value : nil
@@ -58,7 +60,10 @@ extension ByteBuffer {
5860
/// - flags: An instance of MemcacheFlags that holds the flags intended to be serialized and written to the ByteBuffer.
5961
mutating func writeMemcacheFlags(flags: MemcacheFlags) {
6062
// Ensure that both storageMode and arithmeticMode aren't set at the same time.
61-
precondition(!(flags.storageMode != nil && flags.arithmeticMode != nil), "Cannot specify both a storage and arithmetic mode.")
63+
precondition(
64+
!(flags.storageMode != nil && flags.arithmeticMode != nil),
65+
"Cannot specify both a storage and arithmetic mode."
66+
)
6267

6368
if let shouldReturnValue = flags.shouldReturnValue, shouldReturnValue {
6469
self.writeInteger(UInt8.whitespace)

‎Sources/Memcache/MemcacheConnection.swift

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
1313
//===----------------------------------------------------------------------===//
14-
@_spi(AsyncChannel)
15-
16-
import NIOCore
14+
@_spi(AsyncChannel) import NIOCore
1715
import NIOPosix
1816
import ServiceLifecycle
1917

@@ -92,7 +90,7 @@ public actor MemcacheConnection: Service {
9290
let channel = try await ClientBootstrap(group: eventLoopGroup)
9391
.connect(host: self.host, port: self.port)
9492
.flatMap { channel in
95-
return channel.eventLoop.makeCompletedFuture {
93+
channel.eventLoop.makeCompletedFuture {
9694
try channel.pipeline.syncOperations.addHandler(MessageToByteHandler(MemcacheRequestEncoder()))
9795
try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(MemcacheResponseDecoder()))
9896
return try NIOAsyncChannel<MemcacheResponse, MemcacheRequest>(synchronouslyWrapping: channel)
@@ -106,37 +104,42 @@ public actor MemcacheConnection: Service {
106104
requestContinuation: continuation
107105
)
108106

109-
var iterator = channel.inboundStream.makeAsyncIterator()
107+
var iterator = channel.inbound.makeAsyncIterator()
110108
switch self.state {
111109
case .running(_, let channel, let requestStream, let requestContinuation):
112110
for await (request, continuation) in requestStream {
113111
do {
114-
try await channel.outboundWriter.write(request)
112+
try await channel.outbound.write(request)
115113
let responseBuffer = try await iterator.next()
116114

117115
if let response = responseBuffer {
118116
continuation.resume(returning: response)
119117
} else {
120118
self.state = .finished
121119
requestContinuation.finish()
122-
continuation.resume(throwing: MemcacheError(
123-
code: .connectionShutdown,
124-
message: "The connection to the Memcache server was unexpectedly closed.",
125-
cause: nil,
126-
location: .here()
127-
))
120+
continuation.resume(
121+
throwing: MemcacheError(
122+
code: .connectionShutdown,
123+
message: "The connection to the Memcache server was unexpectedly closed.",
124+
cause: nil,
125+
location: .here()
126+
)
127+
)
128128
}
129129
} catch {
130130
switch self.state {
131131
case .running:
132132
self.state = .finished
133133
requestContinuation.finish()
134-
continuation.resume(throwing: MemcacheError(
135-
code: .connectionShutdown,
136-
message: "The connection to the Memcache server has shut down while processing a request.",
137-
cause: error,
138-
location: .here()
139-
))
134+
continuation.resume(
135+
throwing: MemcacheError(
136+
code: .connectionShutdown,
137+
message:
138+
"The connection to the Memcache server has shut down while processing a request.",
139+
cause: error,
140+
location: .here()
141+
)
142+
)
140143
case .initial, .finished:
141144
break
142145
}
@@ -152,19 +155,21 @@ public actor MemcacheConnection: Service {
152155
private func sendRequest(_ request: MemcacheRequest) async throws -> MemcacheResponse {
153156
switch self.state {
154157
case .initial(_, _, _, let requestContinuation),
155-
.running(_, _, _, let requestContinuation):
158+
.running(_, _, _, let requestContinuation):
156159

157160
return try await withCheckedThrowingContinuation { continuation in
158161
switch requestContinuation.yield((request, continuation)) {
159162
case .enqueued:
160163
break
161164
case .dropped, .terminated:
162-
continuation.resume(throwing: MemcacheError(
163-
code: .connectionShutdown,
164-
message: "Unable to enqueue request due to the connection being shutdown.",
165-
cause: nil,
166-
location: .here()
167-
))
165+
continuation.resume(
166+
throwing: MemcacheError(
167+
code: .connectionShutdown,
168+
message: "Unable to enqueue request due to the connection being shutdown.",
169+
cause: nil,
170+
location: .here()
171+
)
172+
)
168173
default:
169174
break
170175
}
@@ -190,7 +195,7 @@ public actor MemcacheConnection: Service {
190195
private func getBufferAllocator() throws -> ByteBufferAllocator {
191196
switch self.state {
192197
case .initial(_, let bufferAllocator, _, _),
193-
.running(let bufferAllocator, _, _, _):
198+
.running(let bufferAllocator, _, _, _):
194199
return bufferAllocator
195200
case .finished:
196201
throw MemcacheError(
@@ -264,7 +269,7 @@ public actor MemcacheConnection: Service {
264269
public func set(_ key: String, value: some MemcacheValue, timeToLive: TimeToLive = .indefinitely) async throws {
265270
switch self.state {
266271
case .initial(_, let bufferAllocator, _, _),
267-
.running(let bufferAllocator, _, _, _):
272+
.running(let bufferAllocator, _, _, _):
268273

269274
var buffer = bufferAllocator.buffer(capacity: 0)
270275
value.writeToBuffer(&buffer)

‎Sources/Memcache/MemcacheError.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public struct MemcacheError: Error, @unchecked Sendable {
3737
}
3838

3939
func copy() -> Self {
40-
return Self(
40+
Self(
4141
code: self.code,
4242
message: self.message,
4343
cause: self.cause,
@@ -111,7 +111,8 @@ extension MemcacheError: CustomStringConvertible {
111111
extension MemcacheError: CustomDebugStringConvertible {
112112
public var debugDescription: String {
113113
if let cause = self.cause {
114-
return "\(String(reflecting: self.code)): \(String(reflecting: self.message)) (\(String(reflecting: cause)))"
114+
return
115+
"\(String(reflecting: self.code)): \(String(reflecting: self.message)) (\(String(reflecting: cause)))"
115116
} else {
116117
return "\(String(reflecting: self.code)): \(String(reflecting: self.message))"
117118
}
@@ -146,7 +147,7 @@ extension MemcacheError {
146147
///
147148
/// - Returns: A multi-line description of the error.
148149
public func detailedDescription() -> String {
149-
return self.detailedDescriptionLines().joined(separator: "\n")
150+
self.detailedDescriptionLines().joined(separator: "\n")
150151
}
151152
}
152153

@@ -229,7 +230,7 @@ extension MemcacheError {
229230
file: String = #fileID,
230231
line: Int = #line
231232
) -> Self {
232-
return SourceLocation(function: function, file: file, line: line)
233+
SourceLocation(function: function, file: file, line: line)
233234
}
234235
}
235236
}

‎Sources/Memcache/MemcacheRequest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import NIOCore
16+
1617
enum MemcacheRequest: Sendable {
1718
struct SetCommand: Sendable {
1819
let key: String

‎Sources/Memcache/MemcacheResponseDecoder.swift

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ struct MemcacheResponseDecoder: NIOSingleStepByteToMessageDecoder {
109109
mutating func next(buffer: inout ByteBuffer) throws -> NextDecodeAction {
110110
// Check if the buffer contains "\r\n"
111111
let bytesView = buffer.readableBytesView
112-
guard let crIndex = bytesView.firstIndex(of: UInt8.carriageReturn), bytesView.index(after: crIndex) < bytesView.endIndex,
113-
bytesView[bytesView.index(after: crIndex)] == UInt8.newline else {
112+
guard let crIndex = bytesView.firstIndex(of: UInt8.carriageReturn),
113+
bytesView.index(after: crIndex) < bytesView.endIndex,
114+
bytesView[bytesView.index(after: crIndex)] == UInt8.newline
115+
else {
114116
return .waitForMoreBytes
115117
}
116118
switch self.nextStep {
@@ -130,7 +132,9 @@ struct MemcacheResponseDecoder: NIOSingleStepByteToMessageDecoder {
130132
return .waitForMoreBytes
131133
}
132134

133-
if let currentByte = buffer.getInteger(at: buffer.readerIndex, as: UInt8.self), currentByte == UInt8.whitespace {
135+
if let currentByte = buffer.getInteger(at: buffer.readerIndex, as: UInt8.self),
136+
currentByte == UInt8.whitespace
137+
{
134138
buffer.moveReaderIndex(forwardBy: 1)
135139
}
136140

@@ -152,7 +156,9 @@ struct MemcacheResponseDecoder: NIOSingleStepByteToMessageDecoder {
152156
return .continueDecodeLoop
153157
}
154158

155-
if let currentByte = buffer.getInteger(at: buffer.readerIndex, as: UInt8.self), currentByte == UInt8.whitespace {
159+
if let currentByte = buffer.getInteger(at: buffer.readerIndex, as: UInt8.self),
160+
currentByte == UInt8.whitespace
161+
{
156162
buffer.moveReaderIndex(forwardBy: 1)
157163
}
158164

@@ -162,7 +168,12 @@ struct MemcacheResponseDecoder: NIOSingleStepByteToMessageDecoder {
162168
self.nextStep = .decodeValue(returnCode, dataLength!, flags)
163169
return .continueDecodeLoop
164170
} else {
165-
let response = MemcacheResponse(returnCode: returnCode, dataLength: dataLength, flags: flags, value: nil)
171+
let response = MemcacheResponse(
172+
returnCode: returnCode,
173+
dataLength: dataLength,
174+
flags: flags,
175+
value: nil
176+
)
166177
self.nextStep = .returnCode
167178
return .returnDecodedResponse(response)
168179
}
@@ -177,10 +188,11 @@ struct MemcacheResponseDecoder: NIOSingleStepByteToMessageDecoder {
177188
}
178189

179190
guard buffer.readableBytes >= 2,
180-
let nextByte = buffer.readInteger(as: UInt8.self),
181-
nextByte == UInt8.carriageReturn,
182-
let nextNextByte = buffer.readInteger(as: UInt8.self),
183-
nextNextByte == UInt8.newline else {
191+
let nextByte = buffer.readInteger(as: UInt8.self),
192+
nextByte == UInt8.carriageReturn,
193+
let nextNextByte = buffer.readInteger(as: UInt8.self),
194+
nextNextByte == UInt8.newline
195+
else {
184196
preconditionFailure("Expected to find CRLF at end of response")
185197
}
186198

‎Sources/Memcache/MemcacheValue.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension MemcacheValue where Self: FixedWidthInteger {
4040
///
4141
/// - Parameter buffer: The ByteBuffer from which the value should be read.
4242
public static func readFromBuffer(_ buffer: inout ByteBuffer) -> Self? {
43-
return buffer.readIntegerFromASCII()
43+
buffer.readIntegerFromASCII()
4444
}
4545
}
4646

@@ -57,7 +57,7 @@ extension MemcacheValue where Self: StringProtocol {
5757
///
5858
/// - Parameter buffer: The ByteBuffer from which the value should be read.
5959
public static func readFromBuffer(_ buffer: inout ByteBuffer) -> Self? {
60-
return buffer.readString(length: buffer.readableBytes) as? Self
60+
buffer.readString(length: buffer.readableBytes) as? Self
6161
}
6262
}
6363

‎Tests/SwiftMemcacheTests/IntegrationTest/MemcacheIntegrationTests.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import Memcache
1615
import NIOCore
1716
import NIOPosix
1817
import XCTest
1918

19+
@testable import Memcache
20+
2021
final class MemcacheIntegrationTest: XCTestCase {
2122
var channel: ClientBootstrap!
2223
var group: EventLoopGroup!
@@ -27,7 +28,9 @@ final class MemcacheIntegrationTest: XCTestCase {
2728
self.channel = ClientBootstrap(group: self.group)
2829
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
2930
.channelInitializer { channel in
30-
return channel.pipeline.addHandlers([MessageToByteHandler(MemcacheRequestEncoder()), ByteToMessageHandler(MemcacheResponseDecoder())])
31+
channel.pipeline.addHandlers([
32+
MessageToByteHandler(MemcacheRequestEncoder()), ByteToMessageHandler(MemcacheResponseDecoder()),
33+
])
3134
}
3235
}
3336

@@ -274,7 +277,11 @@ final class MemcacheIntegrationTest: XCTestCase {
274277

275278
// Get value for key after prepend operation
276279
let updatedValue: String? = try await memcacheConnection.get("greet")
277-
XCTAssertEqual(updatedValue, prependValue + initialValue, "Received value should be the same as the concatenation of prependValue and initialValue")
280+
XCTAssertEqual(
281+
updatedValue,
282+
prependValue + initialValue,
283+
"Received value should be the same as the concatenation of prependValue and initialValue"
284+
)
278285

279286
group.cancelAll()
280287
}
@@ -300,7 +307,11 @@ final class MemcacheIntegrationTest: XCTestCase {
300307

301308
// Get value for key after append operation
302309
let updatedValue: String? = try await memcacheConnection.get("greet")
303-
XCTAssertEqual(updatedValue, initialValue + appendValue, "Received value should be the same as the concatenation of initialValue and appendValue")
310+
XCTAssertEqual(
311+
updatedValue,
312+
initialValue + appendValue,
313+
"Received value should be the same as the concatenation of initialValue and appendValue"
314+
)
304315

305316
group.cancelAll()
306317
}

‎Tests/SwiftMemcacheTests/UnitTest/MemcacheErrorTest.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import Memcache
1615
import XCTest
1716

17+
@testable import Memcache
18+
1819
final class MemcacheErrorTests: XCTestCase {
1920
func testInitialization() {
2021
let location = MemcacheError.SourceLocation(function: "testFunction", file: "testFile.swift", line: 8)
@@ -31,7 +32,12 @@ final class MemcacheErrorTests: XCTestCase {
3132
func testCustomStringConvertible() {
3233
let location = MemcacheError.SourceLocation.here()
3334
let causeError = MemcacheError(code: .protocolError, message: "No response", cause: nil, location: location)
34-
let mainError = MemcacheError(code: .connectionShutdown, message: "Connection lost", cause: causeError, location: location)
35+
let mainError = MemcacheError(
36+
code: .connectionShutdown,
37+
message: "Connection lost",
38+
cause: causeError,
39+
location: location
40+
)
3541

3642
let description = mainError.description
3743

@@ -53,7 +59,12 @@ final class MemcacheErrorTests: XCTestCase {
5359
func testDetailedDescription() {
5460
let location = MemcacheError.SourceLocation.here()
5561
let causeError = MemcacheError(code: .protocolError, message: "No response", cause: nil, location: location)
56-
let mainError = MemcacheError(code: .connectionShutdown, message: "Connection lost", cause: causeError, location: location)
62+
let mainError = MemcacheError(
63+
code: .connectionShutdown,
64+
message: "Connection lost",
65+
cause: causeError,
66+
location: location
67+
)
5768

5869
let detailedDesc = mainError.detailedDescription()
5970

‎Tests/SwiftMemcacheTests/UnitTest/MemcacheFlagsTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import Memcache
1615
import XCTest
1716

17+
@testable import Memcache
18+
1819
final class MemcacheFlagsTests: XCTestCase {
1920
func testVFlag() {
2021
var flags = MemcacheFlags()

‎Tests/SwiftMemcacheTests/UnitTest/MemcacheRequestEncoderTests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import Memcache
1615
import NIOCore
1716
import XCTest
1817

18+
@testable import Memcache
19+
1920
final class MemcacheRequestEncoderTests: XCTestCase {
2021
var encoder: MemcacheRequestEncoder!
2122

@@ -120,7 +121,11 @@ final class MemcacheRequestEncoderTests: XCTestCase {
120121
// Extract the encoded Time-To-Live
121122
let encodedString = outBuffer.getString(at: 0, length: outBuffer.readableBytes)!
122123
let regex = try! NSRegularExpression(pattern: "T(\\d+)", options: .caseInsensitive)
123-
let match = regex.firstMatch(in: encodedString, options: [], range: NSRange(location: 0, length: encodedString.utf16.count))
124+
let match = regex.firstMatch(
125+
in: encodedString,
126+
options: [],
127+
range: NSRange(location: 0, length: encodedString.utf16.count)
128+
)
124129
let encodedTTLRange = Range(match!.range(at: 1), in: encodedString)!
125130
let encodedTTL = Int32(encodedString[encodedTTLRange])!
126131

‎Tests/SwiftMemcacheTests/UnitTest/MemcacheResponseDecoderTests.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import Memcache
1615
import NIOCore
1716
import NIOEmbedded
1817
import XCTest
1918

19+
@testable import Memcache
20+
2021
final class MemcacheResponseDecoderTests: XCTestCase {
2122
var decoder: MemcacheResponseDecoder!
2223

@@ -155,7 +156,10 @@ final class MemcacheResponseDecoderTests: XCTestCase {
155156
// VA 2
156157
var firstPartBuffer = buffer.getSlice(at: buffer.readerIndex, length: splitIndex)!
157158
// \r\nhi\r\n
158-
var secondPartBuffer = buffer.getSlice(at: buffer.readerIndex + splitIndex, length: buffer.readableBytes - splitIndex)!
159+
var secondPartBuffer = buffer.getSlice(
160+
at: buffer.readerIndex + splitIndex,
161+
length: buffer.readableBytes - splitIndex
162+
)!
159163

160164
// Try to decode the first part, which should return .waitForMoreBytes
161165
switch try self.decoder.next(buffer: &firstPartBuffer) {

‎Tests/SwiftMemcacheTests/UnitTest/MemcacheTimeToLiveTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import Memcache
1615
import NIOCore
1716
import XCTest
1817

18+
@testable import Memcache
19+
1920
final class MemcacheTimeToLiveTests: XCTestCase {
2021
let clock = ContinuousClock()
2122

‎Tests/SwiftMemcacheTests/UnitTest/MemcacheValueTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import Memcache
1615
import NIOCore
1716
import XCTest
1817

18+
@testable import Memcache
19+
1920
final class MemcacheValueTests: XCTestCase {
2021
func testMemcacheValueConformance() {
2122
var buffer = ByteBufferAllocator().buffer(capacity: 0)

0 commit comments

Comments
 (0)
Please sign in to comment.