Skip to content

Commit e8bcf7b

Browse files
committed
Add CI for raw temporal types
1 parent 15f568a commit e8bcf7b

File tree

5 files changed

+299
-32
lines changed

5 files changed

+299
-32
lines changed

checklicense.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def find_files_to_check():
2525
('release.toml', ''),
2626
('LICENSE', ''),
2727
('TODO.org', ''),
28+
('tests/ci/*.sql', '--')
2829
]
2930
file_prefixes = dict()
3031
unknown = []

src/convert/raw_temporal.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ use num::Zero;
1414

1515
use crate::{cursor::replies::ResultSet, CursorResult};
1616

17-
use super::{
18-
conversion_error,
19-
raw_decimal::RawDecimal,
20-
FromMonet,
21-
};
17+
use super::{conversion_error, raw_decimal::RawDecimal, FromMonet};
2218

2319
/// Representation of a DATE value from MonetDB
2420
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
@@ -132,6 +128,10 @@ impl RawTime {
132128
};
133129
Ok(time)
134130
}
131+
132+
pub fn microseconds(&self) -> u32 {
133+
self.microseconds + 1_000_000 * self.seconds as u32
134+
}
135135
}
136136

137137
#[test]
@@ -290,21 +290,12 @@ impl RawTz {
290290
#[test]
291291
fn test_parse_tz() {
292292
let mut s: &[u8] = b"+00:00xyz";
293-
assert_eq!(
294-
RawTz::parse(&mut s),
295-
Ok(RawTz { seconds_east: 0 })
296-
);
293+
assert_eq!(RawTz::parse(&mut s), Ok(RawTz { seconds_east: 0 }));
297294
assert_eq!(s, b"xyz");
298295
s = b"-00:00";
299-
assert_eq!(
300-
RawTz::parse(&mut s),
301-
Ok(RawTz { seconds_east: 0 })
302-
);
296+
assert_eq!(RawTz::parse(&mut s), Ok(RawTz { seconds_east: 0 }));
303297
s = b"+01:00";
304-
assert_eq!(
305-
RawTz::parse(&mut s),
306-
Ok(RawTz { seconds_east: 3600 })
307-
);
298+
assert_eq!(RawTz::parse(&mut s), Ok(RawTz { seconds_east: 3600 }));
308299
s = b"+07:30";
309300
assert_eq!(
310301
RawTz::parse(&mut s),
@@ -470,7 +461,10 @@ where
470461
*data = &data[n..];
471462
Ok(v)
472463
}
473-
_ => Err(conversion_error::<T>("invalid integer")),
464+
_ => Err(conversion_error::<T>(format_args!(
465+
"invalid integer {:?}",
466+
BStr::new(data)
467+
))),
474468
}
475469
}
476470

tests/ci/context.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//
77
// Copyright 2024 MonetDB Foundation
88

9-
use anyhow::{bail, Result as AResult};
9+
use anyhow::{bail, Context, Result as AResult};
1010

11-
use monetdb::{ConnectResult, Connection, Cursor, Parameters};
11+
use monetdb::{parms::Parm, ConnectResult, Connection, Cursor, Parameters};
1212
use std::{
1313
env::{self, VarError},
1414
mem,
@@ -22,12 +22,12 @@ const DEFAULT_PASSWORD: &str = "monetdb";
2222

2323
/// This static either holds a mutex-protected Server Context or
2424
/// the error message we got when we tried to create one.
25-
static SERVER: LazyLock<Result<Mutex<Server>, String>> = LazyLock::new(initialize_server);
25+
static SERVER: LazyLock<AResult<Mutex<Server>>> = LazyLock::new(find_and_initialize_server);
2626

2727
/// Get an exclusive handle on the server context, initializing if not already there.
2828
pub fn get_server() -> MutexGuard<'static, Server> {
2929
match &*SERVER {
30-
Err(e) => panic!("{e}"),
30+
Err(e) => panic!("{e:#}"),
3131
Ok(srv) => match srv.lock() {
3232
Ok(guard) => guard,
3333
Err(poisoned) => poisoned.into_inner(),
@@ -69,19 +69,31 @@ pub fn with_shared_cursor(f: impl FnOnce(&mut Cursor) -> AResult<()>) -> AResult
6969
})
7070
}
7171

72-
fn initialize_server() -> Result<Mutex<Server>, String> {
72+
fn find_and_initialize_server() -> AResult<Mutex<Server>> {
7373
match parms_from_env(SERVER_URL_ENV_VAR, Some(DEFAULT_SERVER_URL)) {
7474
Ok(parms) => {
75+
let mut conn = Connection::new(parms.clone())?;
76+
initialize_server(&mut conn).context("Could not initialize test database")?;
7577
let server = Server {
7678
parms,
77-
shared: None,
79+
shared: Some(conn),
7880
};
7981
Ok(Mutex::new(server))
8082
}
81-
Err(e) => Err(format!("{SERVER_URL_ENV_VAR}: {e}")),
83+
Err(e) => bail!("{SERVER_URL_ENV_VAR}: {e}"),
8284
}
8385
}
8486

87+
const SQL: &str = include_str!("schema.sql");
88+
89+
fn initialize_server(conn: &mut Connection) -> AResult<()> {
90+
let mut cursor = conn.cursor();
91+
cursor.execute(SQL)?;
92+
cursor.close()?;
93+
Ok(())
94+
}
95+
96+
/// Extract connection parameters from an environment variable
8597
fn parms_from_env(env_var: &str, default_url: Option<&str>) -> AResult<Parameters> {
8698
let url = match env::var(env_var) {
8799
Ok(u) => u,
@@ -99,11 +111,11 @@ fn parms_from_env(env_var: &str, default_url: Option<&str>) -> AResult<Parameter
99111
.with_user(DEFAULT_USER)?
100112
.with_password(DEFAULT_PASSWORD)?;
101113
parms.apply_url(&url)?;
102-
parms.validate()?;
103114

104-
let test_parms = parms.clone().with_connect_timeout(2)?;
105-
let conn = Connection::new(test_parms)?;
106-
conn.close();
115+
if parms.is_default(Parm::ConnectTimeout) {
116+
parms.set_connect_timeout(2)?;
117+
}
107118

119+
parms.validate()?;
108120
Ok(parms)
109121
}

tests/ci/schema.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- SPDX-License-Identifier: MPL-2.0
2+
--
3+
-- This Source Code Form is subject to the terms of the Mozilla Public
4+
-- License, v. 2.0. If a copy of the MPL was not distributed with this
5+
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
--
7+
-- Copyright 2024 MonetDB Foundation
8+
9+
START TRANSACTION;
10+
11+
DROP TABLE IF EXISTS temporal;
12+
CREATE TABLE temporal(
13+
i INT,
14+
tsz TIMESTAMPTZ
15+
);
16+
17+
-- The interval 87_654 seconds was chosen to get a nice variation
18+
-- in seconds, minutes, hours, days, etc.
19+
-- 1000 * 1000 goes back to about year -748.
20+
INSERT INTO temporal
21+
SELECT
22+
value AS i,
23+
NOW - value * value * INTERVAL '87654' SECOND
24+
FROM
25+
sys.generate_series(0, 1000)
26+
;
27+
-- SELECT * FROM temporal;
28+
29+
COMMIT;

0 commit comments

Comments
 (0)