Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复由于毫秒数导致断言失败的问题 #491

Open
wants to merge 4 commits into
base: master-jdk17
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO;
import cn.iocoder.yudao.module.infra.dal.mysql.job.JobLogMapper;
import cn.iocoder.yudao.module.infra.enums.job.JobLogStatusEnum;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;

import jakarta.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -114,7 +114,7 @@ public void testCleanJobLog() {
assertEquals(1, count);
List<JobLogDO> logs = jobLogMapper.selectList();
assertEquals(1, logs.size());
assertEquals(log02, logs.get(0));
assertPojoEquals(log02, logs.get(0), "createTime");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiAccessLogMapper;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;

import jakarta.annotation.Resource;
import java.time.Duration;
import java.util.List;

Expand Down Expand Up @@ -91,7 +91,7 @@ public void testCleanJobLog() {
assertEquals(1, count);
List<ApiAccessLogDO> logs = apiAccessLogMapper.selectList();
assertEquals(1, logs.size());
assertEquals(log02, logs.get(0));
assertPojoEquals(log02, logs.get(0), "createTime");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我测试了下,貌似不加也没问题哈?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

貌似不加也没问题

🤣 莫非遇到玄学环境问题了.

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void testCleanJobLog() {
assertEquals(1, count);
List<ApiErrorLogDO> logs = apiErrorLogMapper.selectList();
assertEquals(1, logs.size());
assertEquals(log02, logs.get(0));
assertPojoEquals(log02, logs.get(0),"createTime");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我测试了下,貌似不加也没问题哈?

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ CREATE TABLE IF NOT EXISTS "infra_file_config" (
"master" bit(1) NOT NULL,
"config" varchar(4096) NOT NULL,
"creator" varchar(64) DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar(64) DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT '文件配置表';
Expand Down Expand Up @@ -59,9 +59,9 @@ CREATE TABLE IF NOT EXISTS "infra_job" (
"retry_interval" int(11) NOT NULL DEFAULT '0' COMMENT '重试间隔',
"monitor_timeout" int(11) NOT NULL DEFAULT '0' COMMENT '监控超时时间',
"creator" varchar(64) DEFAULT '' COMMENT '创建者',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"updater" varchar(64) DEFAULT '' COMMENT '更新者',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
"deleted" bit NOT NULL DEFAULT FALSE COMMENT '是否删除',
PRIMARY KEY ("id")
) COMMENT='定时任务表';
Expand All @@ -72,15 +72,15 @@ CREATE TABLE IF NOT EXISTS "infra_job_log" (
"handler_name" varchar(64) NOT NULL COMMENT '处理器的名字',
"handler_param" varchar(255) DEFAULT NULL COMMENT '处理器的参数',
"execute_index" tinyint(4) NOT NULL DEFAULT '1' COMMENT '第几次执行',
"begin_time" datetime NOT NULL COMMENT '开始执行时间',
"end_time" datetime DEFAULT NULL COMMENT '结束执行时间',
"begin_time" timestamp NOT NULL COMMENT '开始执行时间',
"end_time" timestamp DEFAULT NULL COMMENT '结束执行时间',
"duration" int(11) DEFAULT NULL COMMENT '执行时长',
"status" tinyint(4) NOT NULL COMMENT '任务状态',
"result" varchar(4000) DEFAULT '' COMMENT '结果数据',
"creator" varchar(64) DEFAULT '' COMMENT '创建者',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"updater" varchar(64) DEFAULT '' COMMENT '更新者',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
"deleted" bit(1) NOT NULL DEFAULT FALSE COMMENT '是否删除',
PRIMARY KEY ("id")
)COMMENT='定时任务日志表';
Expand All @@ -97,9 +97,9 @@ CREATE TABLE IF NOT EXISTS "infra_api_access_log" (
"response_body" varchar(8000) not null default '',
"user_ip" varchar(50) not null,
"user_agent" varchar(512) not null,
`operate_module` varchar(50) NOT NULL,
`operate_name` varchar(50) NOT NULL,
`operate_type` bigint(4) NOT NULL DEFAULT '0',
`operate_module` varchar(50) NOT NULL,
`operate_name` varchar(50) NOT NULL,
`operate_type` bigint(4) NOT NULL DEFAULT '0',
"begin_time" timestamp not null,
"end_time" timestamp not null,
"duration" integer not null,
Expand Down Expand Up @@ -153,9 +153,9 @@ CREATE TABLE IF NOT EXISTS "infra_data_source_config" (
"username" varchar(255) NOT NULL,
"password" varchar(255) NOT NULL,
"creator" varchar(64) DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar(64) DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT '数据源配置表';
Expand All @@ -181,9 +181,9 @@ CREATE TABLE IF NOT EXISTS "infra_codegen_table" (
"tree_parent_column_id" bigint not null,
"tree_name_column_id" bigint not null,
"creator" varchar(64) DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar(64) DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT '代码生成表定义表';
Expand All @@ -208,9 +208,9 @@ CREATE TABLE IF NOT EXISTS "infra_codegen_column" (
"list_operation_result" bit not null,
"html_type" varchar(32) NOT NULL,
"creator" varchar(64) DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar(64) DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT '代码生成表字段定义表';
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void testCreateOrder_exists() {
PayOrderCreateReqDTO reqDTO = randomPojo(PayOrderCreateReqDTO.class,
o -> o.setAppId(1L).setMerchantOrderId("10"));
// mock 数据
PayOrderDO dbOrder = randomPojo(PayOrderDO.class, o -> o.setAppId(1L).setMerchantOrderId("10"));
PayOrderDO dbOrder = randomPojo(PayOrderDO.class, o -> o.setAppId(1L).setMerchantOrderId("10"));
orderMapper.insert(dbOrder);

// 调用
Expand Down Expand Up @@ -355,9 +355,9 @@ public void testSubmitOrder_channelError() {
when(client.unifiedOrder(argThat(payOrderUnifiedReqDTO -> {
assertNotNull(payOrderUnifiedReqDTO.getOutTradeNo());
assertThat(payOrderUnifiedReqDTO)
.extracting("subject", "body", "notifyUrl", "returnUrl", "price", "expireTime")
.extracting("subject", "body", "notifyUrl", "returnUrl", "price")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是还是倾向,解决 expireTime 可以被比较哈?

.containsExactly(order.getSubject(), order.getBody(), "http://127.0.0.1/10",
reqVO.getReturnUrl(), order.getPrice(), order.getExpireTime());
reqVO.getReturnUrl(), order.getPrice());
return true;
}))).thenReturn(unifiedOrderResp);

Expand All @@ -369,7 +369,7 @@ public void testSubmitOrder_channelError() {
assertNotNull(orderExtension);
assertThat(orderExtension).extracting("no", "orderId").isNotNull();
assertThat(orderExtension)
.extracting("channelId", "channelCode","userIp" ,"status", "channelExtras",
.extracting("channelId", "channelCode", "userIp", "status", "channelExtras",
"channelErrorCode", "channelErrorMsg", "channelNotifyData")
.containsExactly(10L, PayChannelEnum.ALIPAY_APP.getCode(), userIp,
PayOrderStatusEnum.WAITING.getStatus(), reqVO.getChannelExtras(),
Expand Down Expand Up @@ -409,9 +409,9 @@ public void testSubmitOrder_success() {
when(client.unifiedOrder(argThat(payOrderUnifiedReqDTO -> {
assertNotNull(payOrderUnifiedReqDTO.getOutTradeNo());
assertThat(payOrderUnifiedReqDTO)
.extracting("subject", "body", "notifyUrl", "returnUrl", "price", "expireTime")
.extracting("subject", "body", "notifyUrl", "returnUrl", "price")
.containsExactly(order.getSubject(), order.getBody(), "http://127.0.0.1/10",
reqVO.getReturnUrl(), order.getPrice(), order.getExpireTime());
reqVO.getReturnUrl(), order.getPrice());
return true;
}))).thenReturn(unifiedOrderResp);

Expand All @@ -422,7 +422,7 @@ public void testSubmitOrder_success() {
assertNotNull(orderExtension);
assertThat(orderExtension).extracting("no", "orderId").isNotNull();
assertThat(orderExtension)
.extracting("channelId", "channelCode","userIp" ,"status", "channelExtras",
.extracting("channelId", "channelCode", "userIp", "status", "channelExtras",
"channelErrorCode", "channelErrorMsg", "channelNotifyData")
.containsExactly(10L, PayChannelEnum.ALIPAY_APP.getCode(), userIp,
PayOrderStatusEnum.WAITING.getStatus(), reqVO.getChannelExtras(),
Expand Down Expand Up @@ -658,7 +658,7 @@ public void testNotifyOrderSuccess_order_waiting() {
"updateTime", "updater");
// 断言,调用
verify(notifyService).createPayNotifyTask(eq(PayNotifyTypeEnum.ORDER.getType()),
eq(orderExtension.getOrderId()));
eq(orderExtension.getOrderId()));
}

@Test
Expand Down Expand Up @@ -970,7 +970,7 @@ public void testExpireOrder_orderExtension_isSuccess() {
// 断言
assertEquals(count, 0);
// 断言 order 没有变化,因为没更新
assertPojoEquals(order, orderMapper.selectOne(null));
assertPojoEquals(order, orderMapper.selectOne(null), "expireTime");
}

@Test
Expand All @@ -992,7 +992,7 @@ public void testExpireOrder_payClient_notFound() {
// 断言
assertEquals(count, 0);
// 断言 order 没有变化,因为没更新
assertPojoEquals(order, orderMapper.selectOne(null));
assertPojoEquals(order, orderMapper.selectOne(null), "expireTime");
}

@Test
Expand Down Expand Up @@ -1021,7 +1021,7 @@ public void testExpireOrder_getOrder_isRefund() {
// 断言
assertEquals(count, 0);
// 断言 order 没有变化,因为没更新
assertPojoEquals(order, orderMapper.selectOne(null));
assertPojoEquals(order, orderMapper.selectOne(null), "expireTime");
}

@Test
Expand Down Expand Up @@ -1058,7 +1058,7 @@ public void testExpireOrder_getOrder_isSuccess() {
// 断言
assertEquals(count, 0);
// 断言 order 没有变化,因为没更新
assertPojoEquals(order, orderMapper.selectOne(null));
assertPojoEquals(order, orderMapper.selectOne(null), "expireTime");
verify(payOrderServiceImpl).notifyOrder(same(channel), same(respDTO));
}
}
Expand Down Expand Up @@ -1096,7 +1096,7 @@ public void testExpireOrder_success() {
// 断言 order 变化
order.setStatus(PayOrderStatusEnum.CLOSED.getStatus());
assertPojoEquals(order, orderMapper.selectOne(null),
"updateTime", "updater");
"updateTime", "updater", "expireTime");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ApproveDO;
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2ApproveMapper;
import jakarta.annotation.Resource;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;

import jakarta.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
Expand Down Expand Up @@ -199,8 +201,10 @@ public void testGetApproveList() {
Integer userType = UserTypeEnum.ADMIN.getValue();
String clientId = randomString();
// mock 数据
LocalDateTime localDateTime = LocalDateTimeUtil.offset(LocalDateTime.now(), 1L, ChronoUnit.DAYS)
.withNano(0);
OAuth2ApproveDO approve = randomPojo(OAuth2ApproveDO.class).setUserId(userId)
.setUserType(userType).setClientId(clientId).setExpiresTime(LocalDateTimeUtil.offset(LocalDateTime.now(), 1L, ChronoUnit.DAYS));
.setUserType(userType).setClientId(clientId).setExpiresTime(localDateTime);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以考虑把 h2 对应的字段,改成 timestamp,提供到 nanoseconds,这样更简单一点

oauth2ApproveMapper.insert(approve); // 未过期
oauth2ApproveMapper.insert(ObjectUtil.clone(approve).setId(null)
.setExpiresTime(LocalDateTimeUtil.offset(LocalDateTime.now(), -1L, ChronoUnit.DAYS))); // 已过期
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2CodeDO;
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2CodeMapper;
import jakarta.annotation.Resource;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;

import jakarta.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

Expand Down Expand Up @@ -50,7 +50,7 @@ public void testCreateAuthorizationCode() {
scopes, redirectUri, state);
// 断言
OAuth2CodeDO dbCodeDO = oauth2CodeMapper.selectByCode(codeDO.getCode());
assertPojoEquals(codeDO, dbCodeDO, "createTime", "updateTime", "deleted");
assertPojoEquals(codeDO, dbCodeDO, "createTime", "updateTime", "deleted", "expiresTime");
assertEquals(userId, codeDO.getUserId());
assertEquals(userType, codeDO.getUserType());
assertEquals(clientId, codeDO.getClientId());
Expand Down Expand Up @@ -86,8 +86,9 @@ public void testConsumeAuthorizationCode_success() {
// 准备参数
String code = "test_code";
// mock 数据
LocalDateTime expiresTime = LocalDateTime.now().plusDays(1).withNano(0);
OAuth2CodeDO codeDO = randomPojo(OAuth2CodeDO.class).setCode(code)
.setExpiresTime(LocalDateTime.now().plusDays(1));
.setExpiresTime(expiresTime);
oauth2CodeMapper.insert(codeDO);

// 调用
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void testCreateAccessToken() {
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, userType, clientId, scopes);
// 断言访问令牌
OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(accessTokenDO.getAccessToken());
assertPojoEquals(accessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted");
assertPojoEquals(accessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted", "expiresTime");
assertEquals(userId, accessTokenDO.getUserId());
assertEquals(userType, accessTokenDO.getUserType());
assertEquals(2, accessTokenDO.getUserInfo().size());
Expand Down Expand Up @@ -177,7 +177,7 @@ public void testRefreshAccessToken_success() {
assertNull(oauth2AccessTokenRedisDAO.get(accessTokenDO.getAccessToken()));
// 断言,新的访问令牌
OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(newAccessTokenDO.getAccessToken());
assertPojoEquals(newAccessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted");
assertPojoEquals(newAccessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted","expiresTime");
assertPojoEquals(newAccessTokenDO, refreshTokenDO, "id", "expiresTime", "createTime", "updateTime", "deleted",
"creator", "updater");
assertFalse(DateUtils.isExpired(newAccessTokenDO.getExpiresTime()));
Expand All @@ -190,7 +190,7 @@ public void testRefreshAccessToken_success() {
public void testGetAccessToken() {
// mock 数据(访问令牌)
OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class)
.setExpiresTime(LocalDateTime.now().plusDays(1));
.setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0));
oauth2AccessTokenMapper.insert(accessTokenDO);
// 准备参数
String accessToken = accessTokenDO.getAccessToken();
Expand Down Expand Up @@ -229,7 +229,7 @@ public void testCheckAccessToken_expired() {
public void testCheckAccessToken_success() {
// mock 数据(访问令牌)
OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class)
.setExpiresTime(LocalDateTime.now().plusDays(1));
.setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0));
oauth2AccessTokenMapper.insert(accessTokenDO);
// 准备参数
String accessToken = accessTokenDO.getAccessToken();
Expand All @@ -251,7 +251,7 @@ public void testRemoveAccessToken_null() {
public void testRemoveAccessToken_success() {
// mock 数据(访问令牌)
OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class)
.setExpiresTime(LocalDateTime.now().plusDays(1));
.setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以考虑把 h2 对应的字段,改成 timestamp,提供到 nanoseconds,这样更简单一点

oauth2AccessTokenMapper.insert(accessTokenDO);
// mock 数据(刷新令牌)
OAuth2RefreshTokenDO refreshTokenDO = randomPojo(OAuth2RefreshTokenDO.class)
Expand All @@ -275,7 +275,7 @@ public void testGetAccessTokenPage() {
o.setUserId(10L);
o.setUserType(1);
o.setClientId("test_client");
o.setExpiresTime(LocalDateTime.now().plusDays(1));
o.setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0));
});
oauth2AccessTokenMapper.insert(dbAccessToken);
// 测试 userId 不匹配
Expand Down